Stupid regex question

Josh ChaitinPollak josh at offthehill.org
Thu Mar 2 11:55:32 EST 2006


I'm trying to detect the presence of a word on a line using sed. Is  
there a way to say something like, 'if the match fails, don't return  
anything'? For example:

pardsbane $ echo "this is a -p param test" | sed -e 's/.*\-p \([a-z]* 
\).*/\1/'
param
pardsbane $ echo "this is a param test" | sed -e 's/.*\-p \([a-z]* 
\).*/\1/'
this is a param test

I would like to modify the search so that in the latter case, nothing  
is returned. In other words, if -p is not present, I would like to  
match the entire line and return nothing. Obviously this can be done  
with a grep before the sed, but I was hoping to do it in one command.




More information about the Discuss mailing list