943,884 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Apr 10th, 2008
0

Re: Unixx shel script - combing information from 2 files into one useing looping structur

can u explain this code please.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyberman111 is offline Offline
24 posts
since May 2007
Apr 10th, 2008
0

Re: Unixx shel script - combing information from 2 files into one useing looping structur

Shell Scripting Syntax (Toggle Plain Text)
  1. while read -r name number
  2. do
  3. while read -r NAME NUM
  4. do
  5. if NAME is equal name
  6. then
  7. echo name NUM number
  8. done < "file2"
  9. 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
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Apr 10th, 2008
0

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
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Apr 12th, 2008
0

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!...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Impact4ever is offline Offline
14 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Required Hardware information in Linux & solaris.
Next Thread in Shell Scripting Forum Timeline: compare 2 files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC