- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- estract content form two file
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
04-19-2005 09:58 PM
04-19-2005 09:58 PM
I have two files, file1 and file2.
I need to extract only those line from file2 that contains line text of file1.
Do I need some scripting or could it be done by concatenating commands ?
Please detail me about.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 10:01 PM
04-19-2005 10:01 PM
Re: estract content form two file
Try "comm -12 file1 file 2" and see if it helps.
Rgds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 10:02 PM
04-19-2005 10:02 PM
Solution1. you want to match the whole line
2. you want the output to go to a new file (file3)
> file3
for i in `cat file2`
do
grep $i file1 >> file3
done
This empties file3 before creating the new file3.
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 10:05 PM
04-19-2005 10:05 PM
Re: estract content form two file
but this is also what i understood from your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 10:08 PM
04-19-2005 10:08 PM
Re: estract content form two file
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 10:09 PM
04-19-2005 10:09 PM
Re: estract content form two file
the comm -12 solution only works for sorted files and matches on complete lines!!
So please sort the files beforehand.
Would it be possible to provide a couple of example lines?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 10:35 PM
04-19-2005 10:35 PM
Re: estract content form two file
maybe 'cause of my nails (like my boss's charming blond secretary !)
;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 11:38 PM
04-19-2005 11:38 PM
Re: estract content form two file
grep -f file1 file2
Else, get every line in file1 and do grep as like as,
while read line; do
grep $line file2
done < file1
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2005 12:34 AM
04-20-2005 12:34 AM
Re: estract content form two file
What if the lines in file 1 have
.*
?
Ouch!
# perl -ne'BEGIN{local@ARGV=("file1");while(<>){$f1{$_}++}}exists$f1{$_}and print' file2 ...
Safe and simple
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2005 12:39 AM
04-20-2005 12:39 AM
Re: estract content form two file
can you please clarify:
1. Are the files sorted
2. Are you interested in matching the whole line of file1 against whole line of file2.
Regards