LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2013, 07:53 AM   #1
scruffbag
LQ Newbie
 
Registered: Sep 2013
Posts: 2

Rep: Reputation: Disabled
Problem using grep to search for multiple strings listed in a file


Hi - I'm having a problem using grep to extract lines from a data file that contain one of several different strings. I am trying to load the strings from a file - hence, the code I'm using is:

grep -f file.containing.strings data.file

When I run this, grep doesn't return any output.

The strings are listed in my file one per line, and I have tried listing the strings in this file both with and without single quotation marks. I have also checked that (at least some of) the strings I'm searching for are definitely in the data file, using the regular:
grep 'string' data.file

Any ideas what I'm doing wrong?

Thanks!
 
Old 09-25-2013, 08:14 AM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,879

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by scruffbag View Post
Any ideas what I'm doing wrong?
Help us to help you. Provide sample input files (10-15 lines will do). Construct a sample output file which corresponds to your sample input and post both samples here. With "Before and After" examples we can better understand your needs and also judge if our proposed solution fills those needs.

Daniel B. Martin
 
1 members found this post helpful.
Old 09-25-2013, 08:16 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
If your strings are not regular expressions you should use -F to indicate that:
Code:
grep -Ff file.containing.strings data.file
If that doesn't work, post the input files: it's hard to help blindly...
 
1 members found this post helpful.
Old 09-25-2013, 08:22 AM   #4
scruffbag
LQ Newbie
 
Registered: Sep 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi - thanks for the responses but I've just managed to solve the problem. I originally created the input file under Windows, so it had Windows line ends (which I was copying and pasting into new files created in Linux). I've just resaved it with Linux line ends and, magically, grep is now working on my file!

Hopefully this might at least help someone else to avoid doing this in future!

Cheers,

Nick
 
1 members found this post helpful.
  


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 multiple strings GEEXTER Linux - General 7 12-06-2013 09:56 PM
[SOLVED] Using grep search with array containing strings and spaces mim747 Linux - Newbie 3 10-17-2011 07:45 PM
[SOLVED] Recursive search for strings in files with a certain date: find -name or grep -R? wolverene13 Linux - Newbie 6 10-01-2011 05:05 PM
[SOLVED] grep multiple strings krist_m Linux - Newbie 4 01-11-2011 11:43 AM
Grep search & replace strings with backslashes? ziphem Linux - Newbie 4 10-21-2007 04:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:36 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