The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
grep unix.com with google



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2009
Registered User
 

Join Date: Oct 2009
Location: UK
Posts: 8
How do i search for the contents of list1 in list2?

hello all,
I have 2 files, list1 and list2.
They can each have several thousand lines each.

I want to check if list2 has any of the contents of list1, perhaps using a grep so that for instance if list1 contained

arb1000

and list2 contained

arb1000tt

It would match this and pipe it out to seperate file, list3.

I have tried a foreach loop but i get error message, "Too many words from ``" and having looked in the forums I am now not even sure if that was the best way of going about it.

Anybody able to advise what the best way to do this sort of thing is?

Many Thanks
  #2 (permalink)  
Old 11-26-2009
dj - the student
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 667
Try:


Code:
grep -f list1 <list2 >list3

  #3 (permalink)  
Old 11-26-2009
Registered User
 

Join Date: Oct 2009
Location: UK
Posts: 8
hi thanks but i receive a message :

grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

should have mentioned I am using a c shell in solaris.

cheers
  #4 (permalink)  
Old 11-29-2009
Registered User
 

Join Date: Oct 2009
Location: UK
Posts: 8
Having read these forums I have now realised that the either of the following seem to do the job :

/usr/xpg4/bin/grep -f file1 < file2

or

egrep -f file1 < file2

I will have to learn the uses of egrep and I am not sure why there seems to be two grep commands but I guess thats the problem with me being a unix newbie

Thanks to all
Cheers
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search a pattern in a file with contents in a single line sparks Shell Programming and Scripting 4 03-17-2009 02:51 AM
Search files with specfic extention and later search content lovi_v UNIX for Advanced & Expert Users 2 07-14-2008 01:05 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
search for the contents in many file and print that file using shell script cdfd123 Shell Programming and Scripting 3 10-07-2007 11:17 PM
Creating file contents using contents of another file ReV Shell Programming and Scripting 21 02-24-2006 10:25 AM



All times are GMT -4. The time now is 10:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0