Skip to main content
Tweak title and text, tags
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

sed comment multi-lineseveral lines

I have a text file test.txttest.txt with something like the following:

foo configure top start fun bar hello 

I want to comment out line numbers 2, 5 &and 7. So, so that the output shouldwould look like:

foo #configure top start #fun bar #hello 

When I use sed -i "2,7 {s/^/#/}" test.txt lines 2,3 3,4 4,5 5,6 & 6 and 7 get commented. How to ensure only specific line numbers are commented? Appreciate any help.

sed comment multi-line

I have a text file test.txt with something like the following:

foo configure top start fun bar hello 

I want to comment out line numbers 2, 5 & 7. So the output should look like:

foo #configure top start #fun bar #hello 

When I use sed -i "2,7 {s/^/#/}" test.txt lines 2,3,4,5,6 & 7 get commented. How to ensure only specific line numbers are commented? Appreciate any help.

sed comment several lines

I have a text file test.txt with something like the following:

foo configure top start fun bar hello 

I want to comment out line numbers 2, 5 and 7, so that the output would look like:

foo #configure top start #fun bar #hello 

When I use sed -i "2,7 {s/^/#/}" test.txt lines 2, 3, 4, 5, 6 and 7 get commented. How to ensure only specific line numbers are commented? Appreciate any help.

Source Link

sed comment multi-line

I have a text file test.txt with something like the following:

foo configure top start fun bar hello 

I want to comment out line numbers 2, 5 & 7. So the output should look like:

foo #configure top start #fun bar #hello 

When I use sed -i "2,7 {s/^/#/}" test.txt lines 2,3,4,5,6 & 7 get commented. How to ensure only specific line numbers are commented? Appreciate any help.