i need to display the mismatches from two files.The output what is get is the entire rows which mismatch from file 1 are displayed first and the corresponding rows from file 2 are displayed below it.
Sample output:
From Test Run 1 - The row count of file2.txt is 23
From Test Run 1 - The row count of file3.txt is 20
From Test Run 1 - The row count of file4.txt is 2
From Test Run 2 - The row count of file2.txt is 22
From Test Run 2 - The row count of file3.txt is 21
From Test Run 2 - The row count of file4.txt is 1
Code used is:
diff -bi 21.txt 22.txt > 13.txt
sed -e '/^-/d' -e '/^[1-9]/d' -e 's/^[<>] //' 13.txt >> ab.out
how can the ouput be displayed this way?
From Test Run 1 - The row count of file4.txt is 2
From Test Run 2 - The row count of file4.txt is 1
From Test Run 1 - The row count of file2.txt is 23
From Test Run 2 - The row count of file2.txt is 22
From Test Run 1 - The row count of file3.txt is 20
From Test Run 2 - The row count of file3.txt is 21
The first file will contain the row count of the files in directory one.
e.g.
A The row count of file2.txt is 23
A The row count of file3.txt is 20
A The row count of file4.txt is 2
The second file will contain the row count of the files in directory two.
e.g.
a The row count of file2.txt is 22
a The row count of file3.txt is 21
a The row count of file4.txt is 1
I am comparing the files ignoring the case and spacing difference.
Finally after comparing i am replacing 'A' with "From Test Run 1 - " and 'a' with "From Test Run 2 - ".
Last edited by ragavhere; 04-29-2008 at 12:31 PM..
Reason: Replacing after comparing
I don't think diff is the right tool here. Can't you just sort on the file name field, and pipe to a simple awk script which compares the last field, and prints as necessary?
I do not know much of scripting.Can you give me a awk script to compare files after sorting which should ignore spacing difference and case and the line which mismatches from file 2 with that of file 1 should be displayed one below the other?
For e.g.
File 1 contains
A The row count of file2.txt is 23
A The row count of file3.txt is 20
A The row count of file4.txt is 2
File 2 contains
a The row count of file2.txt is 22
a The row count of file3.txt is 21
a The row count of file4.txt is 1
Output should be like
A The row count of file2.txt is 23
a The row count of file2.txt is 22
A The row count of file3.txt is 20
a The row count of file3.txt is 21
A The row count of file4.txt is 2
a The row count of file4.txt is 1
Can you give me a awk script to compare files after sorting which should ignore spacing difference and case and the line which mismatches from file 2 with that of file 1 should be displayed one below the other?
Assuming you don't have spaces in the file names or other oddities not visible in your examples, try something like this.
This will print the results for file2.txt then file3.txt then file4.txt etc. If that is a problem then you can sort the output from awk (add | sort -k4 at the very end).
Sorting causes the lines with the same filenn.txt to be adjacent:
The LC_ALL is because the sort order in my locale is different from the default; you might need to add that, too.
Now we only need to check if filennn.txt is the same as on the previous line, and if so, if the row count is different; if so, we print both the previous line and this one. Then we take care to remember the file name, the row count, and the whole line so that the comparison can take place again when the next line comes in.
Quote:
Originally Posted by ragavhere
Will awk be able to compare files of size 20MB?
This reads one line at a time, so doesn't use more memory for bigger files. The sort will be a bottleneck, though, obviously.
I am running diff between two directories dir1 and dir2.
diff --exclude --recursive --brief -b dir1 dir2
The output of the above command is
Files dir1/java/abc/bcd/abc9991.java and dir2/java/abc/bcd/abc9991.java differ
Files dir1/java/abc/bcd/abc9933.java and... (11 Replies)
Hi,
I wasn't sure whether to post this in the dummies or expert section, here's what I'm trying to do, but I suspect I'm missing the boat and should perhaps be using some of diff's builtin output functionality.
diff -yb --suppress-common-lines file1.js file2.js >> ~/results.txt
When I... (5 Replies)
How to get diff to not print the chevrons and the dashes? In this case the differences are all single line differences.
Also the first few lines don't matter. How to get the output to always exclude the first few lines? Thanks! (1 Reply)
hello everyone,
I am trying to compare two files and have the result in a new files. When I used diff I am getting the header, '<' and '>' in my result which I don't want to have it in my output file. :wall:
opt/sam/input: diff file1.txt file2.txt
1,20d0
< 16,ZA,
< ZJ,08,
< Z7,03,
Any... (1 Reply)
I have two files to compare, but diff output doesn't give me decent output I want.
The portion of the two files are shown below.
file 1)
Authorize <1>
Transaction Database Slave 3 <1>
CPM HTTP Proxy Server <1>
SSP (TDB Server) <1>
CPM Application Authorization <7>
CPM Script... (5 Replies)
I'm asking for explanation about the output of the diff format when i compare the two files f1 and f2:
root@host1 # cat f1
205226
205237
205250
205255
205262
205274
205307
205403
205464
205477
205500
205520
205626
205759
205766
205776 (2 Replies)
Hello is there a way to limit the number of lines output by the DIFF command?
I tried -C 200 ect and -c but it continues to print out the whole huge file.
Reason needed is i'm trying to do alot of DIFFs on a long list of files and would like to only get back an indicator which files are... (2 Replies)
I have two CSV files and I would like to create a third CSV file containing the differences between the two.
I understand the diff command can be used to list differences between two files. My problem is that when I pipe the output into a third CSV file, the line numbers and other formatting... (3 Replies)
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)