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
merging text files code19 Shell Programming and Scripting 8 02-13-2008 05:13 AM
Merging two files venommaker UNIX for Dummies Questions & Answers 4 01-10-2008 05:15 AM
merging INPUT and files fiol73 UNIX for Dummies Questions & Answers 1 01-01-2007 02:14 PM
merging two files based on some key Vandana Yadav Shell Programming and Scripting 1 02-03-2006 06:45 AM
merging two files rameshonline Shell Programming and Scripting 13 06-29-2004 03:06 PM

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

Join Date: Jan 2008
Posts: 32
merging of 2 files AWK - part 2

i have try , but i think i will never learn awk
now i have 2 files :

a
1:aaa:2:aaa1
2:bbb:2:bbb1
3:ccc:3:ccc1

b
aaa:2
bbb:0
ccc:3

output:
for all lines where a.$2 == b.$1
i want to compare a.$3 != b.$2 if true then set err=1 if false set err=0
and print all lines from file a + err

Thanks & regards
Peter
Reply With Quote
Forum Sponsor
  #2  
Old 02-11-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
what other languages do you know..? there's no restriction for you if you don't like awk. you can do what you want in most other languages. The standard algo is the same.
1) open file1
2) read a line
3) split the components and get the ones you need to compare
4) open file2
5) read the line
6) split the components and get the ones you need to compare to 3)
7) compare
8) display results
9) close the files
Reply With Quote
  #3  
Old 02-11-2008
Registered User
 

Join Date: Jun 2007
Location: Beijing China
Posts: 495
awk

Hi,
I think this one should be ok for you! Please try.

paste file1 file2 | sed 's/ /:/' > temp
awk 'BEGIN{OFS=FS=":"}
{
if($2==$5)
if($3==$6)
print $1":"$2":"$3":"$4":"0
else
print $1":"$2":"$3":"$4":"1
}' temp
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 06:34 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