Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED multiple line comment 1

Status
Not open for further replies.

blarneyme

MIS
Jun 22, 2009
160
US
I know this is awk, however, since it is closely related to sed...

How do you comment multiple lines at once?

For example:
Code:
# cat text
line 1
line 2
line 3
line 4
line 5
line 6
line 7

And you want to comment lines 2, 4, and 7.
Code:
# sed -i'2 s/^line/#/' text
will comment line two
or
Code:
# sed -i '2,4 s/^line/#/' text
will comment lines 2,3,4

But how to get 2, 4, and 7 at once?
 
want to comment lines 2, 4, and 7
'2s!^!#!;4s!^!#!;7s!^!#!'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top