Link to home
Start Free TrialLog in
Avatar of toooki
toooki

asked on

UNIX grep command question

Is there any way to use grep command to output all lines in a file that has either string "abc" orstring "pqr" or string "xyz" in it?

# cat filename.txt | grep "abc"

I know above works but I want to include in output lines containing string "pqr" or string "xyz" as well. (Also the lines need to be in sequence as in the original file.)
SOLUTION
Avatar of sshah254
sshah254

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toooki
toooki

ASKER

Thank you all for help.

#egrep "abc|pqr|xyz" filename.txt

The above command worked the way I wanted.

#grep -E 'abc|pqr|xyz' filename.txt
above gave me error:
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .

Also similar error with:
grep -e abc -e pqr -e xyz  filename.txt
..

Mine is Solaris 9 server:

#uname -a
SunOS bingofish 5.9 Generic_118558-39 sun4u sparc SUNW,Ultra-60
Wow... sorry... thought -e was part of the base.  We run AIX/HPUX/LINUX
Avatar of toooki

ASKER

Ok no problem.
Many thanks for your help.