DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Shell Scripting (http://www.daniweb.com/forums/forum113.html)
-   -   Unixx shel script - combing information from 2 files into one useing looping structur (http://www.daniweb.com/forums/thread118322.html)

cyberman111 Apr 10th, 2008 1:05 am
Re: Unixx shel script - combing information from 2 files into one useing looping structur
 
can u explain this code please.

eggi Apr 10th, 2008 1:33 am
Re: Unixx shel script - combing information from 2 files into one useing looping structur
 
while read -r name number
do
    while read -r NAME NUM
    do
        if NAME is equal name
        then
              echo name NUM number       
    done < "file2"
done < "file1"

Basically, this pseudo code is reading the first file and grabbing the two variables, and for each line read from the first file, it's checking every line in the second file and, if the name matches, it's print the output in the format you specified to stdout.

If you need Monday to equal Mon, etc, you can do that pretty easily with sed or even cut, if you know you only need a certain number of characters in your abbreviation (like if your standard is always 3 - Monday = Mon, Tuesday = Tue, etc)

Hope that helps. Give it a shot and see what you can do with it. Remember, the code posted is pseudo-code which means it's not entirely "correct" (won't just work if you cut-and-paste it) and is meant to demonstrate a principal and provide a means to reaching the answer rather than being the answer itself.

Best wishes,

, Mike

eggi Apr 10th, 2008 1:41 am
Re: Unixx shel script - combing information from 2 files into one useing looping structur
 
BTW,

Just a friendly tip. You might want to kill the other 3 or 4 identical posts you have in this forum or an admin might delete them all.

Just trying to help out so you don't get bumped off. Hope you get your problem solved soon :)

, Mike

Impact4ever Apr 12th, 2008 10:13 pm
Re: Unixx shel script - combing information from 2 files into one useing looping structur
 
I wished I had seen this post earlier. Cause I had the same home work in my unix class.

It took me a good while, but I got it working with the for loop.

Anywho, happy scripting!...


All times are GMT -4. The time now is 6:23 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC