Operating System - HP-UX
1837582 Members
2988 Online
110117 Solutions
New Discussion

Comment out lines 15 thru 31

 
SOLVED
Go to solution
Shabu Khan-2
Frequent Advisor

Comment out lines 15 thru 31


I see another opportunity to use perl -p -i -e here.

I need to comment out lines 15 through 31 in a xml file.

# perl -ne 'print if 21 .. 31' server.xml

prints lines 21 thru 31, I need to comment these:


Thoughts?

Thanks,
Shabu
3 REPLIES 3
Hein van den Heuvel
Honored Contributor
Solution

Re: Comment out lines 15 thru 31



This 'one liner' will do that:

$ perl -pe 'BEGIN{$f = shift; $l=shift} s/^// if $.==$l ' 15 21 test.xml

fwiw,
Hein.
James R. Ferguson
Acclaimed Contributor

Re: Comment out lines 15 thru 31

Hi Shabu:

# perl -pi -e 's/(.*)/#$1/ if 21..31' file

Regards!

...JRF...
Shabu Khan-2
Frequent Advisor

Re: Comment out lines 15 thru 31

Thanks for responding folks.

I went ahead and used this solution and did inplace editing.

# perl -p -i.bak -e 'BEGIN{$f = shift; $l=shift} s/^// if $.==$l' 21 36 server.xml

Closing this out.

Thanks,
Shabu