- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: compare entries in two files
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
Forums
Discussions
Discussions
Discussions
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
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
01-10-2011 09:20 AM
01-10-2011 09:20 AM
compare entries in two files
I have two files and would like the output to only contain data that is not duplicated across both files.
filea contains:
a
b
c
i
j
k
fileb contains:
a
b
c
d
e
f
g
h
i
j
k
desired output
d
e
f
g
h
- Tags:
- comm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2011 09:38 AM
01-10-2011 09:38 AM
Re: compare entries in two files
$ comm -3 file1 file2
-1: filter data only in file1
-2: filter data only in file2
-3: filter data in both files
If your first file contains a "filter" for file2
$ comm -13 file1 file2
or if you have GNU grep (but that is slower)
$ grep -F -x -f file1 file2
If file1 contains patters to filer out of file2
$ grep -v -f file1 file2
Note that in that case each line in file1 is expanded as being a regular expression
If unsorted and may contain dups, this lists all lines only in either file:
$ perl -wne'$e{$_}{$ARGV}++}END{print for sort grep{keys%{$e{$_}}==1}keys%e' file1 file2
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2011 09:41 AM
01-10-2011 09:41 AM
Re: compare entries in two files
;^)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2011 09:47 AM
01-10-2011 09:47 AM
Re: compare entries in two files
for x in `cat filea filebb|sort -u`;do
[ "$(cat a b|grep -w $x|wc -l)" -eq 1 ] && echo $x
done
;^)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2011 08:09 PM
01-10-2011 08:09 PM
Re: compare entries in two files
Please run this command.
diff filea fileb | awk ' $1==">" || $1=="<" { print $2 }'