[NTLUG:Discuss] removing text: fighting tr and regex
    Stuart Johnston 
    saj at thecommune.net
       
    Thu Jul  6 09:54:02 CDT 2006
    
    
  
Victor Brilon wrote:
> If you truly want to use the ? qualifier to do what it's supposed to  
> do (i.e., match the minimal number of chars), just use perl like this:
> echo "jdoe at example.com (John Doe)" | perl -n -e 's/\(.*?\)//g;print'
In the spirit of TMTOWTDI, you can use the -p option instead of -n so 
you don't need the print statement.  Also, if you have a file, or files, 
you want to in-place edit, you can use the -i option (after backing up, 
of course (you can also have perl make backups for you but I usually 
prefer to do it myself)).
perl -p -i -e 's/\(.*?\)//g' file.txt
When I have trouble remembering these options, I just think of the tasty 
round desserts (or the mathematical constant if you are so inclined :).
-Stuart
    
    
More information about the Discuss
mailing list