![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
awk 'BEGIN{FS=OFS=","}
FNR==NR{arr[$2]=$1;next}
$4 in arr{print $4,arr[$4],$1}
' file1 file2
|
|
#3
|
|||
|
|||
|
thanks for the feedback...I will try to incorporate this into my script
|
|||
| Google The UNIX and Linux Forums |