LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-13-2014, 05:54 AM   #1
rstengel
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Rep: Reputation: Disabled
Searching text with another file


Is there a way to search a text file with a list of words from another file?

File 1 has list of words:
first
second
third
...

File 2 has a lot of text:
Search this file with all the words in File 1
 
Old 11-13-2014, 07:59 AM   #2
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
I think this does exactly what you want

Code:
grep -f file1 file2
where file1 contains the terms you want to find in file2.

You may be interested (or not) in -i as well:

Code:
       -f FILE, --file=FILE
              Obtain  patterns  from  FILE,  one  per  line.   The  empty file
              contains zero patterns, and therefore matches nothing.   (-f  is
              specified by POSIX.)

       -i, --ignore-case
              Ignore  case  distinctions  in  both  the  PATTERN and the input
              files.  (-i is specified by POSIX.)
man grep for the various output options.
 
2 members found this post helpful.
Old 11-13-2014, 08:03 AM   #3
slucas263
LQ Newbie
 
Registered: Nov 2014
Location: Brazil
Distribution: Debian, Ubuntu
Posts: 2

Rep: Reputation: Disabled
UoU.. Nice command @goumba
\0/ Thanks..
 
Old 11-14-2014, 01:30 AM   #4
rstengel
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
That works great and so simple. I didn't know it would be that easy.
Thanks
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] searching a text file arn2025 Linux - Newbie 2 02-03-2012 02:02 AM
SuSE 9.3 - searching for specific text in file - Command line options? EnderX Linux - Newbie 1 04-15-2010 01:45 PM
Q: Searching text within a file WITHOUT regular expressions stormcloud Linux - General 1 07-30-2009 04:41 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
Searching a text file - complicated cyph3r7 Linux - General 2 12-16-2003 10:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:41 AM.

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
Open Source Consulting | Domain Registration