- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- command or script for equal lines in 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-22-2004 12:57 AM
01-22-2004 12:57 AM
I need a HP-UX command or simple script that outputs the lines that are occuring in two textfiles (like the opposite of the diff command).
Example :
File A contains
Abc
Acc
Bcc
Fil B contains
Acc
Acdc
Bcc
Bde
The desired output would be :
Acc
Bcc
Thanks for your help.
Franky
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:02 AM
01-22-2004 01:02 AM
Re: command or script for equal lines in files
while read $line
do
grep $line file2
done < file1
AQ bit slow for big files though so maybe awk or perl is what you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:03 AM
01-22-2004 01:03 AM
Re: command or script for equal lines in files
Try "man 1 comm".
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:04 AM
01-22-2004 01:04 AM
Re: command or script for equal lines in files
"comm -3 FileA FileB"
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:10 AM
01-22-2004 01:10 AM
Re: command or script for equal lines in files
Thanks for these replies coming so fast.
I only knew of the cmp and diff command, but indeed comm -12 does the job.
Thanks,Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:10 AM
01-22-2004 01:10 AM
Re: command or script for equal lines in files
comm -12 A B
gives you the required output.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:23 AM
01-22-2004 01:23 AM
Re: command or script for equal lines in files
sed -e 's|^|^|' -e 's|$|$|' fileA >fileA.tmp
grep -f fileA.tmp filB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:27 AM
01-22-2004 01:27 AM
Re: command or script for equal lines in files
.*
? :) :)
you could do that with GNU grep
# gnu-fgrep -x -f fileA fileB
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 01:41 AM
01-22-2004 01:41 AM
Re: command or script for equal lines in files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 03:01 AM
01-22-2004 03:01 AM
Re: command or script for equal lines in files
I like the funny Elmar's one ... It should work even with lines like .* if he uses 'grep -Fx' :^)
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 04:55 PM
01-22-2004 04:55 PM
Re: command or script for equal lines in files
With the capitals in the example it should work better (start of line is forced with the capital) but if Accccdefed was in filB, it would show up...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 09:25 PM
01-22-2004 09:25 PM
Re: command or script for equal lines in files
I meant that I liked your grep -f tip. But with -Fx you don't even need the sed and the temporary file :
-x for exact lines (so no sed needed for ^ and $)
-F for fixed strings (prevent from lines containing .*)
So the answer could simply be :
grep -Fxf fileA fileB
which gives the same result as :
comm -12 fileA fileB
In fact in this case there is even no need to work on sorted files which is easier.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2004 04:46 AM
01-24-2004 04:46 AM
Re: command or script for equal lines in files
lt09:/tmp 166 > perl -le'print chr(65+int rand 26),map{chr(97+int rand 26)}1..5 for 1..50000' | sort > x0
lt09:/tmp 167 > perl -le'print chr(65+int rand 26),map{chr(97+int rand 26)}1..5 for 1..50000' | sort > x1
lt09:/tmp 168 > time comm -12 x0 x1 > x01.0
0.020u 0.000s 0:00.00 0.0% 0+0k 0+0io 123pf+0w
lt09:/tmp 169 > time grep -Fxf x0 x1 > x01.1
0.300u 0.020s 0:00.31 103.2% 0+0k 0+0io 136pf+0w
lt09:/tmp 170 > perl -le'print chr(65+int rand 26),map{chr(97+int rand 26)}1..5 for 1..500000' | sort > x0
lt09:/tmp 171 > perl -le'print chr(65+int rand 26),map{chr(97+int rand 26)}1..5 for 1..500000' | sort > x1
lt09:/tmp 172 > time comm -12 x0 x1 > x01.0
0.150u 0.010s 0:00.08 200.0% 0+0k 0+0io 123pf+0w
lt09:/tmp 173 > time grep -Fxf x0 x1 > x01.1
4.230u 0.060s 0:04.32 99.3% 0+0k 0+0io 136pf+0w
lt09:/tmp 174 >
this was on linux, where GNU grep is the default, but HP-UX will show similar results
So *IF* you would decide to go for fgrep (equal to grep -F), be sure to put the smallest file in front
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2004 04:59 AM
01-24-2004 04:59 AM
Re: command or script for equal lines in files
the commands are not the same, and with the fgrep command the output might differ if the files are swapped. This is because handling of double lines is different in comm and grep.
watch this, from the last example:
lt09:/tmp 178 > ll x[01]*
246644 -rw-rw-rw- 1 merijn users 3500000 2004-01-24 18:42 x0
246692 -rw-rw-rw- 1 merijn users 5544 2004-01-24 18:42 x01.0
246693 -rw-rw-rw- 1 merijn users 5551 2004-01-24 18:42 x01.1
246691 -rw-rw-rw- 1 merijn users 3500000 2004-01-24 18:42 x1
lt09:/tmp 179 > diff x01*
444a445
> Pgpcds
Exit 1
lt09:/tmp 180 > grep Pgpcds x[01]*
x0:Pgpcds
x01.0:Pgpcds
x01.1:Pgpcds
x01.1:Pgpcds
x1:Pgpcds
x1:Pgpcds
lt09:/tmp 181 >
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 07:41 AM
01-28-2004 07:41 AM
Re: command or script for equal lines in files
(FYI only)
Enjoy, Have FUN! H.Merijn