awk script required to compare two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script required to compare two files
# 8  
Old 03-21-2011
awk file comparison - only 512 lines getting processed

Hi,

Thanks for all your suggestion.

And the below executes and gives output only for 512 lines.

I am having files around 8000 lines.

Is anything i need to change in script .

Thank you,
K.Vasanth
# 9  
Old 04-01-2011
If file2 has unmatching ID's print as blank

Hi,

Thanks for the replies.

Few more doubts raised, like file1 col3, does not matches with file2 col2, then the output must contain file2 as output with blank columns .

Eg:

Code:
file1:
No;age;id;name
1;24;37h;name1
2;22;67e;name2
4;48;9r;name3
6;67;9i8;name4

file2:
exp;id;pos
23;9r;hr
15;67e;tec
16;u67;thi
18;  ;iol 


Expected new file output:

No;age;id;name;exp;pos
4;28;9r;name3;23;hr
2;24;37h;name1;15;tec
  ;16;u67;         ;    ;thi
  ;18;     ;         ;    ;iol

Thanks
Vasanth
# 10  
Old 04-01-2011
Code:
 awk -F";" 'NR==FNR{a[$3]=$0;next}{if(a[$2]){print a[$2],$1,$3}else{print " ",$1,$2," "," ",$3}}' OFS=";" file1 file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies

2. Shell Programming and Scripting

[awk] Compare two files

HI!! I am trying to compare two files using AWK but I have some problems. I need to count how many times letters are used in two texts. This is my script { long=length($0) for (i=1;i<=long;i++) { aux=substr($0,i,1) if ( aux != " " && aux != "" ) ... (7 Replies)
Discussion started by: ettore8888
7 Replies

3. Shell Programming and Scripting

How to use awk shell script to compare and match two files?

Basically, I have two files dupestest.txt 152,153 192,193,194 215,216 290,291 2279,2280 2282,2283haftest.txt 152,ABBOTS ROAD 153,ABBOTS ROAD 154,ABBOTS ROAD 155,ABBOTS ROAD 156,ABBOTS ROAD 157,ABBOTS ROADI want to find the numbers in dupestest.txt in haftest.txt... (4 Replies)
Discussion started by: amyc92
4 Replies

4. Shell Programming and Scripting

Compare files using awk

Please help me to compare two files and remove the items in file2 from file1 file 1:delimited using pipe(|) file1 00012|Description - 1|||||AA12345|1|AB12345|2|2012/06/03 AB123|Description - 2|||||AA12345|3|ZA11111|4|2012/06/04 11111|Description - 3|||||AP00012|1|AB12345|2|2012/06/03... (8 Replies)
Discussion started by: Mary James
8 Replies

5. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

6. Shell Programming and Scripting

awk script required

File 1 ################### TRAIU DSKDL; SLLA ;LAKJA KJAJA NSAJAN JANAL AJKJA JAJALA KAKAK JA AKA AKA AJ A A PPIN TRY1 SANT1 PPIN TRY2 SANT2 PPIN TRY3 SANT3 PPIN TRY4 SANT4 PPIN TRY5 SANT5 AJJA NA ANA ANHDJLD ALJALJA AJLJAJD LALJAL ALJALJA ALJALJA (4 Replies)
Discussion started by: jaita
4 Replies

7. UNIX for Advanced & Expert Users

Solution required for awk script

Hi Jim, The following script is in working state. But i m having one more problem with awk cmd. Could you tell me how to use any variable inside awk or how to take any variable value outside awk. My problem is i want to maintain one property file in which i am declaring variable value into that... (1 Reply)
Discussion started by: Ganesh Khandare
1 Replies

8. Shell Programming and Scripting

using awk to compare two files

Hi, I have two tab separated files; file1: S.No ddi fi cu o/l t+ t- 1 0.5 0.6 o 0.1 0.2 2 0.2 0.3 l 0.3 0.4 3 0.5 0.8 l 0.1 0.6 file2: S.No ddi fi cu o/l t+ t- 1 0.8 0.9 o 0.5 0.6 2 0.5 0.2 o 0 0 3 0.2 0.3 l 0 0 4 0.5 0.6 l 0 0 (1 Reply)
Discussion started by: vasanth.vadalur
1 Replies

9. Shell Programming and Scripting

awk compare 2 files

Hi i hope some awk gurus here can help me.. here is what i need i have 2 files: File1 152445 516532 405088.pdf 152445 516533 405089.pdf 152491 516668 405153.jpg 152491 520977 408779.jpg 152491 0 409265.pdf File2 516532 /tmp/MainStreet_Sum09_Front_FNL.pdf 516533... (9 Replies)
Discussion started by: kenray
9 Replies

10. Shell Programming and Scripting

AWK script help required

Hello every one i have a very long file 'file1' like this <K>1</K> </Condition> <Tariff>Rate <Price>1.27</Price> <Interval>30</Interval> </Tariff> </Node> <Node>NonFaF <Tariff>Rate <Price>1.9</Price> <Interval>30</Interval> </Tariff> </Node> </Node> </Node> <Node>FaF (9 Replies)
Discussion started by: Dastard
9 Replies
Login or Register to Ask a Question