comparing two pipe delimited files

Hi,

  I was looking for a quick but reliable way to compare two flat files A and B. Both are pipe delimited. They have the same columns and hence same data format and ordering.
I am looking to see if file A differs from file B in any columns 1-199. Both have a total of 200 columns and the last column values are known to be different.

Is there a way to do this in unix?
LuckyLucksAsked:
Who is Participating?
 
wilcoxonCommented:
This should do it...
cut -d \| -f 1-199 < file1 > /tmp/cut1
cut -d \| -f 1-199 < file2 > /tmp/cut2
diff -ub /tmp/cut1 /tmp/cut2

Open in new window


Alternately, it would be simple to write up a perl script (or likely awk) to do this.
0
 
LuckyLucksAuthor Commented:
>head -10 results.txt
341,342c341,342
< |||||||||||||||||||||||||||||||||||
< |-12.055556|0.090909|-0.818182|||||228.000000|0.000000|15.000000|1205.000000||0.655589|-2.217391|-1.565217|-6.141079||||||||||||||||||-51.000000|
---
> |||||||||||||||||||||||||||||||||||1
> 778|-12.055556|0.090909|-0.818182||||1|228.000000|0.000000|15.000000|1205.000000||0.655589|-2.217391|-1.565217|-6.141079||||||||||||||||||-51.000000|2
344,345c344,345
< |||||||||||||||||||||||||||||||||||
< |||||||||||||||||||||||||||||||||||


WOuld you have an idea how to read this difference. I compared 98-133.
0
 
wilcoxonCommented:
The top section (above ---) is from file 1 (indicated by the < at the start of the line) and the bottom section is from file 2 (indicated by the >).

You could try "diff -cb" instead for a different output format you might like better.

If you want to know specifically which fields differ, you'll have to use perl, awk, or some other programming language (sort of in the case of awk).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.