- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Match 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
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
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
04-09-2012 11:09 PM
04-09-2012 11:09 PM
Match two files
I have two files , the content is as below , I would like to list the lines in file2 , that the lines the file1 have , as the below , both files have aaaa , cccc , eeee , so the output is the line which have aaaa , cccc , eeee , can advise what can i do ? thx
file1
=====
aaaa
bbbb
cccc
dddd
eeee
file2
=====
aaaa 1111
cccc 2222
eeee 3333
my desired result is as below
=============================
aaaa 1111
cccc 2222
eeee 3333
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2012 03:43 PM
04-10-2012 03:43 PM
Re: Match two files
You can simply use: fgrep -f file1 file2
if you are worried about substrings in file1 that may match multiple lines in file2, you can add -w:
grep -w -f file1 file2
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2012 10:01 PM
04-10-2012 10:01 PM
Re: Match two files
Hi There, you can try this with awk:
$ awk 'NR==FNR {a[$1]=$1;next} {print a[$1],$2}' file1 file2
Cheers,
Raj D.
- Tags:
- awk