LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 08-09-2018, 10:41 PM   #1
Natraj
LQ Newbie
 
Registered: Aug 2018
Posts: 1

Rep: Reputation: Disabled
Multiple strings


Hello,

1)How can we find the multiple strings using the command "grep"?
2)And, what should be the effective command to find a file and inside a string in it.
 
Old 08-10-2018, 12:39 AM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,844

Rep: Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222
Print lines with string1 OR string2t
Code:
egrep "string1|string2"
Code:
grep -e "string1" -e "string2"
Code:
grep "string1
string2"
Like this the grep reads from stdin.
If one more argument follows it is a filename where grep reads from.
If more than one arguments follow they are filenames where grep reads from, and a matching line is printed with the filename prefixed (separated with a colon).
 
Old 08-10-2018, 01:21 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,161

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Has to be homework ...
 
Old 08-10-2018, 01:42 AM   #4
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,174

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Do you mean like this sample below:

Quote:
LIST="some string with a substring you want to match"
SOURCE="substring"
if echo "$LIST" | grep -q "$SOURCE"; then
echo "matched";
else
echo "no match";
fi
Taken from this link: https://stackoverflow.com/questions/...rep-a-variable
 
  


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 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
using sed to replace multiple strings castor0troy Linux - Newbie 7 04-29-2013 11:42 AM
swatch - How to look for multiple strings brownwrap Linux - Security 2 02-03-2012 09:17 PM
[SOLVED] grep multiple strings krist_m Linux - Newbie 4 01-11-2011 11:43 AM
How to find multiple strings into multiple files ? moicpit Linux - General 10 04-25-2010 11:19 AM

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

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