English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

5 answers

I would use the cut command to chop out the fields I want to compare and then use diff on the resulting chopped files.

Suppose you only want to compare the fields 1,2,3, and 7 of a CSV (comma-separated values) file, ignoring all other field values. Just use the following commands sequence:

cut -f1-3,7 -d',' report_1.csv > report_1.xxx
cut -f1-3,7 -d',' report_2.csv > report_2.xxx
diff report_1.xxx report_2.xxx

The first command creates a file report_1.xxx, which contains all the lines from report_1.csv, but containing only fields 1 through 3 and field 7 from each line (where ',' (comma) is the specified field delimiter). The second command does the same for the second report.

If we are talking about comparing to columns of fields within a single file (say field 2 vs. field 4), the command sequence is similar:

cut -f2 -d',' report_1.csv > col2.xxx
cut -f4 -d',' report_1.csv > col4.xxx
diff col2.xxx col4.xxx

You could also do this comparison with an awk or perl script, but that has a much higher learning curve. Each requires you to learn a scripting language, plus you would have to write your own difference engine in that language.

The third command uses diff to compare the resulting files.

2006-06-28 10:40:32 · answer #1 · answered by BalRog 5 · 1 0

If you mean like grep, you can use 'cut' to select the field(s) you want to grep.

If it's file vs file, time to get out gcc and write code.

2006-06-28 10:17:03 · answer #2 · answered by sheeple_rancher 5 · 0 0

You can use "diff" to find the differences in two files. You can always break up the file if you need to. This might not be what you need though . . .

2006-06-28 09:31:15 · answer #3 · answered by thatgirl 6 · 0 0

yes there is a command that does that

2006-06-28 09:30:33 · answer #4 · answered by Anonymous · 0 0

try sed

2006-06-28 10:17:12 · answer #5 · answered by sinkablehail1978 5 · 0 0

fedest.com, questions and answers