- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Command opposite to diff
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
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
тАО01-28-2004 05:37 AM
тАО01-28-2004 05:37 AM
I'm looking for a unix (hpux 11.00) command that does just reverse of diff command. instead of showing lines that are different, I want it to show lines that are the same.
can someone tell me please!!
Thanks,
Sailesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 05:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 05:46 AM
тАО01-28-2004 05:46 AM
Re: Command opposite to diff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 05:46 AM
тАО01-28-2004 05:46 AM
Re: Command opposite to diff
'comm' is the one you are looking for. Look at the man page of comm. You are interested in -3 option which is "Lines that appear in both files".
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 05:50 AM
тАО01-28-2004 05:50 AM
Re: Command opposite to diff
perhaps the comm command could be useful...
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 05:56 AM
тАО01-28-2004 05:56 AM
Re: Command opposite to diff
Sailesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 06:01 AM
тАО01-28-2004 06:01 AM
Re: Command opposite to diff
Although I always use comm, it should be noted that
sdiff -l file1 file2
will show only identical lines on the left side of output.
and
sdiff file1 file2
will outpout lines w/o a "|", "<" or ">" that are identical.
and finally
sdiff -o file.out file1 file2
will print identical lines unaltered but will prompt for action on diffs.
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 06:02 AM
тАО01-28-2004 06:02 AM
Re: Command opposite to diff
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=388167
It's actually "comm -12" - try it!
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 06:08 AM
тАО01-28-2004 06:08 AM
Re: Command opposite to diff
-1 don't show lines only in file 1
-2 don't show lines only in file 2
-3 don't show lines in both files
comm is the command, but the option is not -3, but -12
And please also read thread http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=388167 where the same question is answwred in more depth, and I also post what differs between comm, and the perl and sed solution that also work on unsorted files:
perl -e'$f=pop;%l=map{$_=>1}<>;@ARGV=($f);for(<>){exists$l{$_}and print}' fileA fileB
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 06:13 AM
тАО01-28-2004 06:13 AM
Re: Command opposite to diff
Pete is correct. comm -12 will display the common lines provided the files are sorted. So, you will need to create two temporary files and then use comm against them.
Comm with -3 suppresses column 3. So, you would use
comm file1 file2 |awk '{print $3}'
to get the result which is as same as comm -12
Key is that the files are to be sorted.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 06:19 AM
тАО01-28-2004 06:19 AM
Re: Command opposite to diff
In fact it is a mere context miss
Column 1: Lines that appear only in file1,
Column 2: Lines that appear only in file2,
Column 3: Lines that appear in both files.
Where the context is "comm produces a three column output".
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 06:38 AM
тАО01-28-2004 06:38 AM
Re: Command opposite to diff
Try below yourself, because the forum strips whitespace!
lt09:/home/merijn 101 > cat >x0
aa
bb
dd
ff
gg
hh
lt09:/home/merijn 102 > cat >x1
aa
cc
ff
hh
lt09:/home/merijn 103 > comm x0 x1
aa
bb
cc
dd
ff
gg
hh
lt09:/home/merijn 104 >
And now with duplicate lines (still sorted!)
lt09:/home/merijn 104 > cat > x0
aa
bb
dd
ff
ff
gg
hh
lt09:/home/merijn 105 > cat >x1
aa
cc
ff
hh
hh
lt09:/home/merijn 106 > comm x0 x1
aa
bb
cc
dd
ff
ff
gg
hh
hh
lt09:/home/merijn 107 > perl -e'$f=pop;%l=map{$_=>1}<>;@ARGV=($f);for(<>){exists$l{$_}and print}' x0 x1
aa
ff
hh
hh
lt09:/home/merijn 108 > lt09:/home/merijn 108 > perl -e'$f=pop;%l=map{$_=>1}<>;@ARGV=($f);for(<>){exists$l{$_}and print}' x1 x0
aa
ff
ff
hh
lt09:/home/merijn 109 >
Hope this sheds some light
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 06:46 AM
тАО01-28-2004 06:46 AM
Re: Command opposite to diff
grep -f file1 file2
If we want a simple solution. No sorting is needed.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 06:57 AM
тАО01-28-2004 06:57 AM
Re: Command opposite to diff
what if file1 has wildcards?
# cat >file1
.*
# cat >file2
aa
bb
# grep -f file1 file2
aa
bb
# grep -f file2 file1
#
as also from the other thread one uses GNU grep, it might work:
# grep -xFf file1 file2
but not all of us are so lucky to have taken the time to have HP's grep replaced with GNU grep
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2004 07:37 AM
тАО01-28-2004 07:37 AM
Re: Command opposite to diff
-Sri