Diff with ignoring certain fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Diff with ignoring certain fields
# 1  
Old 11-16-2009
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
Code:
 
123|456|xxx
000|456|xxx

File 2
Code:
 
123|456|yyy
111|456|yyy

# 2  
Old 11-16-2009
Why not create two files without the third column and then do your diff... ?
# 3  
Old 11-16-2009
bit hacky, but you could do something along lines of:
Code:
#  paste -d"|" file1 file2 | nawk -F"|" '!($1==$4&&$2==$5){OFS="|";print "line "NR" \nfile1: "$1,$2,$3 "\nfile2: "$4,$5,$6}'
line 2
file1: 000|456|xxx
file2: 111|456|yyy

HTH
# 4  
Old 11-16-2009
How about (bash/ksh):

Code:
$> diff <(sort infile1|sed 's/|[^|]*$//') <(sort infile2|sed 's/|[^|]*$//')
1c1
< 000|456
---
> 111|456

# 5  
Old 11-19-2009
Thanks ppl.

Went for the simple approach in the end and used Cabraos method of just creating new files without the offending fields.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

2. 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

3. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

4. UNIX for Dummies Questions & Answers

diff original new ignoring changes, just adds and deletes

Hi everyone, I have 2 very large files (each file have about 600k lines) and I want to see which numbers in file1 are not in file2, I thought of doing a diff, however diff will also display the changes, instead of just adds and delete, this makes it very hard to sort out just the adds and deletes.... (1 Reply)
Discussion started by: robertrobert905
1 Replies

5. Shell Programming and Scripting

using diff to on two file but ignoring the last comma separate value

Hi guys I have two file which I sdiff. ie file 1: AA,12,34,56,,789,101,,6666 file 2: AA,12,34,56,,789,101,,7777 The last comma separated value will always change from one day to the next. Is there another unix utility I can use that will sdiff two files but ignore the last comma... (1 Reply)
Discussion started by: wny201
1 Replies

6. Shell Programming and Scripting

.procmailrc and uudeview (put attachments from diff senders to diff folders)

Moderator, please, delete this topic (1 Reply)
Discussion started by: optik77
1 Replies

7. 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

8. Shell Programming and Scripting

Simulate SVN diff using plain diff

Hi, svn diff does not work very well with 2 local folders, so I am trying to do this diff using diff locally. since there's a bunch of meta files in an svn directory, I want to do a diff that excludes everything EXCEPT *.java files. there seems to be only an --exclude option, so I'm not sure... (3 Replies)
Discussion started by: ackbarr
3 Replies

9. UNIX for Dummies Questions & Answers

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. ... (1 Reply)
Discussion started by: harish.madu
1 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question