diff based on fields


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers diff based on fields
# 1  
Old 08-28-2008
diff based on fields

Hi,

I want to perform diff on 2 files & print the lines which first field is different.

e.g.
file 1:
12,23,ask
23,12,bcd

file2:
12,14,bac
24,13,ecf

I want the output as:
23,12,bcd

means: lines from file 1 which are not there in file 2 & not having the same starting field.

Thanks in Advance,
Harish
# 2  
Old 08-28-2008
$ cat diff1
12,23,ask
23,12,bcd

$ cat diff2
12,14,bac
24,13,ecf


$ cat diff3.ksh
BEGIN {
FS=","
}
FNR == NR { if (FNR==1) file1=FILENAME; arr[NR]=$1; LINE=$0; next }
{
if ($1 != arr[FNR])
{
printf("%s\n",LINE);
}
}

$ awk -f diff3.ksh diff1 diff2
23,12,bcd
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

2. Shell Programming and Scripting

Join fields in a same file based on condition

I have an input file like this... All iI want to do is If the lines are identical except for the last field i want to merge them into single line input_file I feel something is nothing I feel something is everything apple mango banana apple mango grapes I want to get output like this:... (3 Replies)
Discussion started by: raj_k
3 Replies

3. Shell Programming and Scripting

File comparing and appending based on fields

I want to compare 2 files, locus_file.txt is a very large file and attr.txt is a small file. I want to match the first 2 columns of the first file to the second column of attr.txt and print the attributes together. locus_file.txt:large file LOC_Os02g47020, LOC_Os03g57840,0.88725114... (3 Replies)
Discussion started by: Sanchari
3 Replies

4. Shell Programming and Scripting

Compare three files based on two fields

Guys, I tried searching on the internet and I couldn't get the answer for this problem. I have 3 files. First 2 fields of all of them are of same type, say they come from various databases but first two fields in the 3 files means the same. I need to verify the entries that are not present... (4 Replies)
Discussion started by: PikK45
4 Replies

5. Shell Programming and Scripting

substitution of fields based on header from another file

I have two files File1 with position (chromosome:start) and individuals as header, where pos is something like 1:2000 and every individual has a value. I have many columns and rows, here an example (tab separated): pos ind1 ind2 ind3 indn... 1:2000 0 0.1 0.1 1 1:2500 0.99 0.2 0.1 0.2 2:1000... (2 Replies)
Discussion started by: kuin
2 Replies

6. Shell Programming and Scripting

compare 2 CSV fields from same diff output

Attached is a file called diff.txt It is the output from this command: diff -y --suppress-common-lines --width=5000 1.txt 2.txt > diff.txt I have also attached 1.txt and 2.txt for your convenience. Both 1.txt and 2.txt contain one very long CSV string. File 1.txt is a CSV dump of... (0 Replies)
Discussion started by: gvolpini
0 Replies

7. Shell Programming and Scripting

How to combine two files based on fields?

I have two files which are as follows: File 1: 1 abc 250 2 pqr 300 3 xyz 100 File 2: 1 abc 230 2 pqr 700 3 xyz 500 Now I need output File, File 3as: S.No Name Count1 Count2 1 abc 250 230 2 pqr 300 700 3 xyz 100 500 NOTE: (13 Replies)
Discussion started by: karumudi7
13 Replies

8. Shell Programming and Scripting

awk to compare diff output by fields

Diff output as follows: < AAA BBB CCC DDD EEE 123 > PPP QQQ RRR SSS TTT 111 > VVV WWW XXX YYY ZZZ 333 > AAA BBB CCC DDD EEE 124 How can i use awk to compare the last field to determine if the counter has increased, and need to ensure that the first 4 fields must have the same... (15 Replies)
Discussion started by: ux4me
15 Replies

9. Shell Programming and Scripting

Compare two files based on values of fields.

Hi All, I have two files and data looks like this: File1 Contents #Field1,Field2 Dist_Center_file1.txt;21 Dist_Center_file3.txt;20 Dist_Center_file2.txt;20 File2 Contents (*** No Header ***) Dist_Center_file1.txt;23 Dist_Center_file2.txt;20 Dist_Center_file3.txt;20 I have... (4 Replies)
Discussion started by: Hangman2
4 Replies

10. Shell Programming and Scripting

Diff with ignoring certain fields

Hi all, I would lke to compare two pipe delimited files but I already expect one field to be different and would like to disregard this field. So for the example below I would like to disregard field three and show line 1 as no difference but line 2 as a difference. Any ideas? File 1 ... (4 Replies)
Discussion started by: pxy2d1
4 Replies
Login or Register to Ask a Question