- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to select common entry between 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
06-21-2005 07:32 PM
06-21-2005 07:32 PM
$cat file1
user1
user2
user3
user4
$cat file2
user1
user3
user5
user7
user10
I need how to select common fileld between these 2 file ( i.e. in this example user1 & user3 are common in both file )
Thx
Abhijeet
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 07:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 07:51 PM
06-21-2005 07:51 PM
Re: How to select common entry between two files
sort it,
keep only duplicates.
Translated in shell :
cat file1 file2 | sort | uniq -d
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 07:57 PM
06-21-2005 07:57 PM
Re: How to select common entry between two files
grep -f
There is a problem that file1 has to be less or equal lines with file2. You can try with script as,
#!/bin/ksh
FILE1=file1
FILE2=file2
if [[ $(wc -l ${FILE1} |cut -d" " -f1) -lt $(wc -l ${FILE2} |cut -d" " -f1) ]]
then
grep -f ${FILE1} < ${FILE2}
else
grep -f ${FILE2} < ${FILE1}
fi
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 08:01 PM
06-21-2005 08:01 PM
Re: How to select common entry between two files
Can you try and solve with comm command?
-- file1 --
user1
user2
user3
user4
user10
user11
-- file2 --
user1
user3
user5
user7
user10
# comm -12 file2 file1
user1
user3
# comm -12 file1 file2
user1
user3
grep + script is working and sort file1 file2 | uniq -d is also working.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 08:14 PM
06-21-2005 08:14 PM
Re: How to select common entry between two files
Abhijeet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 08:14 PM
06-21-2005 08:14 PM