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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-10-2003, 06:27 PM
|
#1
|
LQ Newbie
Registered: Nov 2002
Posts: 15
Rep:
|
grep multiple strings
This may be a simple question for some of ya.
I would like to grep with multiple strings.... for example:
netstat -anp | grep 45632 | grep 23000 | grep 1100
I know the above command doesn't work, but I'm looking for something similar. I would like to search netstat for multiple greps. I would like the command to return all lines that have 45632, all lines that have 23000, and all lines that have 1100.
Any clue?
|
|
|
07-10-2003, 06:39 PM
|
#2
|
Senior Member
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181
Rep:
|
http://www.nevis.columbia.edu/cgi-bin/man.sh?man=grep
I haven't had to grep multiple strings like that, but perhaps grepping the first, routing it to a file, grepping the second, appending the file, and grepping the third, appending to the same file. Then pop open your "results" (or whatever) file and you'll have all your responses. May not be pretty, but at least it's a start, neh?
|
|
|
07-10-2003, 07:42 PM
|
#3
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
egrep my friend... egrep
try this:
netstat -anp | egrep '(45632)|(23000)|(1100)'
regular expressions kick much arse.
|
|
|
07-10-2003, 08:00 PM
|
#4
|
LQ Newbie
Registered: Nov 2002
Posts: 15
Original Poster
Rep:
|
THANKS GUYS
egrep works great!
|
|
|
07-10-2003, 08:15 PM
|
#5
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
It turns out you can use plain old grep too... After some experimenting:
netstat -anp | grep '45632\|23000\|1100'
That should do the same thing. So the question is:
Which do you like more: backslashes or parentheses? 
|
|
1 members found this post helpful.
|
07-23-2012, 01:23 AM
|
#7
|
LQ Newbie
Registered: Jul 2012
Posts: 1
Rep: 
|
suppress multiple lines in a file
Hi Dark_helmet,
i have two lines to supress in one file, how can i do it using "grep -v" command can u please help me in this
thanks,
karthik
|
|
|
12-06-2013, 09:56 PM
|
#8
|
LQ Newbie
Registered: Dec 2013
Posts: 1
Rep: 
|
Nice .thank u:)
i find it very useful. Thank you Dark_Helmet  \ -this is used to suppress the | and then it is used as pipe operator in grep
right?
|
|
|
All times are GMT -5. The time now is 02:37 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|