Comparing two linux files for diffirences and similarities.
Dear friends,
Iam having the following two linux files. file :1 123 456 789 987 654 321 file :2 123 258 236 456 458 658 987 321 568 963 458 758 854 569 Now i want the following out puts 1. similar nos in both the file 1 and file 2 > output= File 3; 2. In file 1, but not in file 2 > out put= file 4; 3. In file 2, but not in file 1 > output = file 5; The command sdiff is giving output with symbols > < | etc, and the such output file is not clear and ready to print. I want to print directly the output files. PL SUGGEST ME THE SUITABLE COMMANDS OR AWK COMMANDS. AND ALSO TELL ME WHERE I HAVE TO WRITE AWK PROGRAMS AND HOW TO RUN IT. HELP ME RAO |
Sounds like all you need is the plain old `diff` command, perhaps with the --GTYPE-group-format=GFMT option.
Get file one but not in file 2: Code:
diff %< file file > output Code:
diff %> file file > output Code:
diff %= file file > output There are other ways of getting only one file's different lines, still using diff. `diff` also has lots of options for formatting the output - read the man page for details, and experiment with it. :) If you want to use `awk`, either write an awk script (a plain text file basically) using a shebang like #!/usr/bin/awk -f or if you wish, just write a bash script (again, basically a text file) with a shebang like #!/bin/bash and within the bash script, send data into `awk` either via a pipe, or by telling awk to read the file you want to operate on. Both methods (the scripts) can be executed from your console terminal. P.S. - if `diff` alone is not producing precisely the output you want (like if it still has < or > symbols you don't want) then pipe the output through something like `sed` or `tr` to remove unwanted characters. EDIT: Added info: Code:
diff --left-column file1 file2 # show only file1 stuff |
It is not working. it is showing to go to help --diff.
Pl guide me Rao |
I couldn't get the diff produce the wanted output either, quickly enough, so I wrote a small&ugly perl script to do the job. Here goes...
Code:
#!/usr/bin/perl |
So it turns out the diff stuff sasha put up does work although I had to do an extended version (Lines from post #2 did not work for me as is):
Code:
#diff %< file file > output |
Right, so I was missing the 2nd option all the way. Thanks to grail for updating my knowledge by another piece :)
It appears this work workstation, having a different variant of Linux than at home, has an older man page for (also older) diff, which is somewhat easier to understand on this part (or then it's just easier after getting it working). However the man page does not define the format for the options in any way, which is odd because running Code:
diff --help |
All times are GMT -5. The time now is 05:03 PM. |