[NTLUG:Discuss] removing text: fighting tr and regex

Richard Geoffrion ntlug at rain4us.net
Thu Jul 6 11:31:24 CDT 2006


Victor Brilon wrote:
> On Jul 6, 2006, at 3:03 AM, Richard Geoffrion wrote:
>
>   
>> echo "jdoe at example.com (John Doe)" | sed --expression s/\(.*?\)//g
>>     
>
> You're almost there:
> echo "jdoe at example.com (John Doe)" | sed -e s/\(.*\)//g
>
> To badly paraphrase "The Princess Bride": You keep using the ?  
> qualifier, I don't think it does what you think it does :)
>
>   
Actually... I think I DO understand what the "?" does.. it prevents the 
following from happening....

$ echo "jdoe at example.com (John Doe), jane at example.com (Jane Doe)" | sed 
s/\(.*\)//g
jdoe at example.com

Without the ?, the expression is GREEDY and takes more than I want..... 
but obviously the expression WITH the "?" still doesn't work at the bash 
prompt. :(

The PERL statement DOES work with the multiple parenths "( )" though.... 
I just wish I understood why it doesn't work in bash/sed/tr.

-- 
Richard






More information about the Discuss mailing list