LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-01-2015, 11:03 PM   #1
AndrewNZ
LQ Newbie
 
Registered: Nov 2013
Posts: 16

Rep: Reputation: Disabled
find words in a file


Hi,

how can I in bash give a file (eg words.txt) with a list of words ,how can I find if one of those are in another file eg filename.eml

Thanks

Andrew
 
Old 12-01-2015, 11:56 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,140

Rep: Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935
"man grep"
 
Old 12-02-2015, 12:43 PM   #3
debguy
Member
 
Registered: Oct 2014
Location: U.S.A.
Distribution: mixed, mostly debian slackare today
Posts: 207

Rep: Reputation: 19
$ cat searchfile | grep -f patternfile

# you said if, if so this line just shows yes/no

$ cat searchfile | grep -q -f patternfile && echo "yes"

# you didn't say if words.txt is a file with one word per line
# if words.txt is a kinda "text file not a list", this may help,
# it uses awk to print "words" each on their own line

$ cat words.txt | awk '{n=0;while(++n<=NF){print $n}}' > patternfile
# note: words.txt should not have grep patterns (ie, '*') unless intended for matching
 
Old 12-02-2015, 01:44 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
Quote:
Originally Posted by debguy View Post
$ cat searchfile | grep -f patternfile

# you said if, if so this line just shows yes/no

$ cat searchfile | grep -q -f patternfile && echo "yes"

# you didn't say if words.txt is a file with one word per line
# if words.txt is a kinda "text file not a list", this may help,
# it uses awk to print "words" each on their own line

$ cat words.txt | awk '{n=0;while(++n<=NF){print $n}}' > patternfile
# note: words.txt should not have grep patterns (ie, '*') unless intended for matching
https://en.wikipedia.org/wiki/Cat_(U...ess_use_of_cat
 
Old 12-02-2015, 07:09 PM   #5
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,642

Rep: Reputation: 277Reputation: 277Reputation: 277
check out this link it might help:

Search eml file contents

http://quickbytesstuff.blogspot.sg/2...-contents.html

Last edited by JJJCR; 12-02-2015 at 07:10 PM. Reason: edit
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep a file and find multiple words and take action accordingly. hbchok Linux - Newbie 5 11-04-2012 06:50 PM
Can I use grep to find two words near each other? walterbyrd Linux - Software 4 12-09-2011 11:01 PM
[SOLVED] Command to find in each file and replace one or two words Sha_unix Linux - Newbie 7 11-22-2011 01:44 PM
regex problem to find min,max length words in file gvanto Linux - Newbie 4 01-30-2011 05:34 PM
find a key words in a file ashley75 Linux - General 3 08-29-2007 04:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration