[kwlug-disc] comment matching lines in multiple files

Raul Suarez rarsa at yahoo.com
Sun Sep 20 17:01:23 EDT 2009


The following command will do it

sed -i -e 's/\(.*\)foobar/#\1foobar/' <filepattern>

for example

 
sed -i -e 's/\(.*\)foobar/#\1foobar/' *.sh

This will do an in-place replacement.

Raul Suarez


Technology consultant
Software, Hardware and Practices
_________________
http://rarsa.blogspot.com/ 
An eclectic collection of random thoughts



----- Original Message ----
From: Richard Weait <richard at weait.com>
To: KWLUG discussion <kwlug-disc at kwlug.org>
Sent: Sunday, September 20, 2009 4:05:11 PM
Subject: Re: [kwlug-disc] comment matching lines in multiple files

On Sun, Sep 20, 2009 at 4:04 PM, Richard Weait <richard at weait.com> wrote:
> Dear Lazyweb,
>
> I have many files, some have lines containing "foobar" in the line
> somewhere.  I want to comment every line that contains "foobar" with a
> leading "#".  From bash.
>
> I'm presuming that there are bash, awk, find, sed and perl one liners for this.

Solution with the least line noise wins.  So I guess perl is out.  ;-)

_______________________________________________
kwlug-disc_kwlug.org mailing list
kwlug-disc_kwlug.org at kwlug.org
http://astoria.ccjclearline.com/mailman/listinfo/kwlug-disc_kwlug.org



      __________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now
http://ca.toolbar.yahoo.com.




More information about the kwlug-disc mailing list