Adding a "3" character at eh beginning of a line.

Adding a "3" character at eh beginning of a line.

am 05.11.2007 17:34:24 von btna

Hi all,

What would be a simple way to add a "#" (Comment) to the beginning of
a specific line on a file?

The file contains different strings and I need to comment on ethat has
a specific word on it:

Original File:

This is a test

I need to add a comment (#) to the above line if it conatins the word
"test"

Thanks in advance,

BTNA

Re: Adding a "3" character at eh beginning of a line.

am 05.11.2007 17:41:46 von Tiago Peczenyj

On Nov 5, 2:34 pm, btna wrote:
> Hi all,
>
> What would be a simple way to add a "#" (Comment) to the beginning of
> a specific line on a file?
>
> The file contains different strings and I need to comment on ethat has
> a specific word on it:
>
> Original File:
>
> This is a test
>
> I need to add a comment (#) to the above line if it conatins the word
> "test"
>
> Thanks in advance,
>
> BTNA

Ok, this is your file
$ cat filename
This is a test

Use a simple sed 1 liner :

$ sed '/test/s/^/# /' filename
# This is a test

see the -i option

$ sed -i.old '/test/s/^/# /' filename

$ cat filename
# This is a test

$ cat filename.old
This is a test