commenting out lines between two delimiters

Hi All,
I am struggling to get my head around the following issue.

I am having to comment out lines between two delimiters by placing an asterix in position 7 but retain all lines in the file and in the same order.

so for example a file containing:

...
...
DELIM1
...
...
DELIM2
...
...

should be converted to:

...
...
* DELIM1
* ...
* ...
* DELIM2
...
...

end of example (... indicates line of text)

I can select the lines to be commented using

 
awk '/DELIM1/,/DELIM2/' file.in

but how do I merge the changed and unchanged lines into a single file and keep them all in the same order.

Thanks in advance.

try this:

awk '/DELIM1/,/DELIM2/ {sub(/^/,"\* ");print;next;} {print;}' file.in > file.out
1 Like

The final result was:

awk '/DELIM1/,/DELIM2/ {sub((substr($0,7,1)),"\*");print;next;} {print;}' file.in > file.out

This places an asterix in position 7,

Thanks the help is appreciated.