- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Need to find the difference of two files and r...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2009 01:04 AM
тАО09-06-2009 01:04 AM
Need to find the difference of two files and redirects to a third file
Example:
File1 :
1
2
3
4
File 2 :
1
3
4
Difference :
2
Thanks in adavance
Kumar jeevan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2009 01:29 AM
тАО09-06-2009 01:29 AM
Re: Need to find the difference of two files and redirects to a third file
cat file1 file2 | sort | uniq -u > file3
If you don't mind a bit of extra information about the differences, *and* want the differences in exact order, then
diff file1 file2 > file3
With the diff command and your example files, file3 would contain:
2d1
< 2
Meaning: "2" exists in file1 but not in file2 ("<" points to file1), and it would be on the 2nd line in file1 ("2d1" indicates the line numbers on file1 and file2, respectively).
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2009 01:57 AM
тАО09-06-2009 01:57 AM
Re: Need to find the difference of two files and redirects to a third file
I just need to apply a Left outer join with First file containg only one column with the second file also containing the same column to fetch the codes present in First file but not in the second file)
Third file should contain only the codes present in First file but not in the second file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 03:47 AM
тАО09-07-2009 03:47 AM
Re: Need to find the difference of two files and redirects to a third file
grep -v -f File2 File1
2
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 03:05 PM
тАО09-07-2009 03:05 PM
Re: Need to find the difference of two files and redirects to a third file
Are the files sorted? If so, you can just use comm(1):
comm -13 file1 file2 > file3
Does the second file have the same number of columns?
>Ivan: You can use grep as well:
>grep -v -f File2 File1
With a million records, this will give terrible performance. Sorting both files and then doing comm(1) will beat that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2009 03:55 AM
тАО10-26-2009 03:55 AM
Re: Need to find the difference of two files and redirects to a third file
sdiff file1 file2 >>output