|
Home > Archive > Unix Shell > October 2006 > compare files
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| tester 2006-10-21, 1:27 am |
| Hi Gurus,
i am looking for script wherein compare two files and generate a third
file which has output from one file which is not present on other.
e.g. file1 and file2 -> file3
file3 should have all the contents form file1 which is not there in
file2.
I did sorted file1 and file2 and ran comm -3 file1 file2 > file3 but
it doesn't contain the output lokking for.
Any help is greatly appreciated
TIA
| |
| Chris F.A. Johnson 2006-10-21, 1:27 am |
| On 2006-10-21, tester wrote:
> Hi Gurus,
> i am looking for script wherein compare two files and generate a third
> file which has output from one file which is not present on other.
>
> e.g. file1 and file2 -> file3
>
> file3 should have all the contents form file1 which is not there in
> file2.
>
> I did sorted file1 and file2 and ran comm -3 file1 file2 > file3 but
> it doesn't contain the output lokking for.
comm -13 file1 file2 > file3
comm -23 file1 file2 > file3
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| Robert Katz 2006-10-21, 1:27 am |
| tester wrote:
> Hi Gurus,
> i am looking for script wherein compare two files and generate a third
> file which has output from one file which is not present on other.
>
> e.g. file1 and file2 -> file3
>
> file3 should have all the contents form file1 which is not there in
> file2.
>
> I did sorted file1 and file2 and ran comm -3 file1 file2 > file3 but
> it doesn't contain the output lokking for.
> Any help is greatly appreciated
> TIA
>
If you want all the lines in file1 that are not in file2,
awk 'NR == FNR { a[$0]; next } !($0 in a)' file2 file1
If you want only uniq lines in file1 that are not in file2,
awk 'NR == FNR { a[$0]; next } !($0 in a) { print; a[$0] }' file2
file1
--
Regards,
---Robert
| |
| Michael Paoli 2006-10-21, 7:31 pm |
| tester wrote:
> i am looking for script wherein compare two files and generate a third
> file which has output from one file which is not present on other.
> e.g. file1 and file2 -> file3
> file3 should have all the contents form file1 which is not there in
> file2.
> I did sorted file1 and file2 and ran comm -3 file1 file2 > file3 but
> it doesn't contain the output lokking for.
Have a look here:
news:1158818522.030928.321780@m73g2000cwd.googlegroups.com
| |
| tester 2006-10-23, 1:16 pm |
|
Thanks Michael Paoli..
That Helped....
> Have a look here:
> news:1158818522.030928.321780@m73g2000cwd.googlegroups.com
|
|
|
|
|