Re: grep command ...

 
SOLVED
Go to solution
Manuales
Super Advisor

grep command ...

hi ...
how can i use grep command to get several lines with different words.
i mean for example
file contains:
pablo
roberto
ana
arturo
enrique
hugo

how can i use grep command to get the lines with words "ana" and "arturo" ?

cat file | grep ana ...how code this?
thanks in advance.
Manuales
7 REPLIES 7
Manuales
Super Advisor

Re: grep command ...

sorry
i will not work with a file, i will work with the result of other command ....
i mean ... something like this:

pl1=`/etc/ping $a 512 -n 1 | grep unknown`
pl2=`/etc/ping $a 512 -n 1 | grep "bytes from"`

i do not want to use two times ping command, i want to use only one variable keeping the words unknown and/or bytes from in case exist ....

how can i use grep command here?
James R. Ferguson
Acclaimed Contributor
Solution

Re: grep command ...

Hi Manuales:

# ping host -n 1|grep -E "bytes from|unknown"

This is a regular expression alternation (or).

Regards!

...JRF...
Manuales
Super Advisor

Re: grep command ...

thank you so much .... taking advantage, i am not very sure about 512 number when you run ping command , what does it mean?
James R. Ferguson
Acclaimed Contributor

Re: grep command ...

Hi (again) Manuales:

> .... taking advantage, i am not very sure about 512 number

It's the packet size. By default 'ping' uses a size of 64. Those manpages are very friendly :-) [ man ping(1M) ].

Regards!

...JRF...
Suraj K Sankari
Honored Contributor

Re: grep command ...

Hi,
>>how can i use grep command to get the lines with words "ana" and "arturo"
You can use below command for grep

#grep -e ana -e arturo filename

Suraj

Dennis Handly
Acclaimed Contributor

Re: grep command ...

You can do this several ways. Using -e makes it visible on the command line. You can put them in a file with "-f search-file".
You can also use newlines:
grep ana^J
arturo^J
file

>JRF: This is a regular expression alternation (or).

-E uses the egrep ERE hammer. Using -e just has a series of REs.
Bhadresh
Trusted Contributor

Re: grep command ...

Hi Manuales,

Please use following command:

#(ping 15.146.157.203 512 2 2> /dev/null) |grep -E "bytes from|unknown"

Regards,
Bhadresh