Fedora Linux Support Community & Resources Center
  #1  
Old 24th July 2009, 09:52 PM
roddomi Offline
Registered User
 
Join Date: Jan 2008
Posts: 6
grep a space-separated list of string

Hi,

How can I grep a space-separated list of strings from a file. For example, say I want to find the lines in file.txt that have the strings Monday or Tuesday in it.

LOOKFOR="Monday Tuesday"
grep $LOOKFOR file.txt (this doesn't work)

I tried using grep -F but it requires the list to be separated by newlines (not spaces).

Thanks,

Rodrigo
Reply With Quote
  #2  
Old 24th July 2009, 10:46 PM
scottro Offline
Retired Community Manager -- Banned from Texas by popular demand.
 
Join Date: Sep 2007
Location: NYC
Posts: 8,142
egrep -i "Monday|Tuesday" filename

Or LOOKFOR="Monday|Tuesday"

egrep -i $LOOKFOR filename

(The -i makes it case-insensitive)
__________________
--
http://home.roadrunner.com/~computertaijutsu

Do NOT PM forum members with requests for technical support. Ask your questions on the forum.


"I don't know why there is the constant push to break any semblance of compatibility" --anon
Reply With Quote
Reply

Tags
grep, list, spaceseparated, string

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How-to realocate space from empty hard drive space to Fedora Core 5 partiton JoeyJoJoe Guides & Solutions (No Questions) 3 3rd February 2008 04:09 PM
server glx vendor string: SGI server glx version string: 1.2 akp Installation, Upgrades and Live Media 4 25th November 2007 07:04 PM
server glx vendor string: SGI, server glx version string: 1.2 + ATI X1950 akp Using Fedora 1 2nd September 2007 02:56 AM
sed regex string replacement after match string issue adosch Using Fedora 10 29th June 2007 04:07 PM
"grep" username in samba or grep file owner? overlord Servers & Networking 0 22nd July 2005 02:12 PM


Current GMT-time: 03:38 (Friday, 25-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat