- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- Need to find the difference of two files and redir...
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP