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 and shell scripting languages 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 09: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 03:26 AM
multi file editing in vi ricl999 Shell Programming and Scripting 0 04-21-2006 08:23 AM
Multi User Multi Task Reza Nazarian UNIX for Dummies Questions & Answers 6 04-13-2006 10:23 AM
multi-file multi-edit kielitaide UNIX for Dummies Questions & Answers 12 06-28-2001 04:12 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2008
orahi001 orahi001 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 48
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
  #2 (permalink)  
Old 01-08-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,345

Code:
awk 'BEGIN{FS=OFS=","}
FNR==NR{arr[$2]=$1;next}
$4 in arr{print $4,arr[$4],$1}
' file1 file2

Regards
  #3 (permalink)  
Old 01-10-2008
orahi001 orahi001 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 48
thanks for the feedback...I will try to incorporate this into my script
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0