The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK Multi-Line Records Processing RacerX Shell Programming and Scripting 10 10-18-2007 05:46 PM
Have a shell script check for a file to exist before processing another file heprox Shell Programming and Scripting 3 11-14-2006 12:26 AM
multi file editing in vi ricl999 Shell Programming and Scripting 0 04-21-2006 04:23 AM
Multi User Multi Task Reza Nazarian UNIX for Dummies Questions & Answers 6 04-13-2006 06:23 AM
multi-file multi-edit kielitaide UNIX for Dummies Questions & Answers 12 06-28-2001 12:12 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-08-2008
Registered User
 

Join Date: Dec 2007
Posts: 34
Multi File processing

Hello,

I have 2 csv files:
File1:
Name,year,organization
Jim,2007,Org1
Bob,1999,Org3
Chris,2001,Org2


File2:
DocumentName,DocumentTitle,organization,year
Test1,Test1,Org1,2007
Test2,Test2,Org2,2008
Test3,Test3,Org3,2009


Using the ksh, I'm reading by line and grabbing the value in the 2nd column ($2). I want to use this value and search the second file to find a line with a match. If it is found I want to grab the value of column 1 ($1) of the second file during that read


while readline
do
if test $i -ge 1;
then
echo "$line" awk '{print $1","$2}' >> File3

now use $2 to search File2 for a match
if found print the value of $1 in File2 to File3
fi
done < $File1


Result
Jim,2007,Test1

Can anyone give me some insight as to how this can be done?


thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-08-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,329
Code:
awk 'BEGIN{FS=OFS=","}
FNR==NR{arr[$2]=$1;next}
$4 in arr{print $4,arr[$4],$1}
' file1 file2
Regards
Reply With Quote
  #3  
Old 01-10-2008
Registered User
 

Join Date: Dec 2007
Posts: 34
thanks for the feedback...I will try to incorporate this into my script
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0