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

Reply

Join Date: May 2007
Posts: 24
Reputation: cyberman111 is an unknown quantity at this point 
Solved Threads: 0
cyberman111 cyberman111 is offline Offline
Newbie Poster

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

 
0
  #11
Apr 10th, 2008
can u explain this code please.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

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

 
0
  #12
Apr 10th, 2008
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

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

 
0
  #13
Apr 10th, 2008
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 14
Reputation: Impact4ever is an unknown quantity at this point 
Solved Threads: 0
Impact4ever's Avatar
Impact4ever Impact4ever is offline Offline
Newbie Poster

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

 
0
  #14
Apr 12th, 2008
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!...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC