Results 1 to 6 of 6
Dears,
Does sed or other command edit the 1st line and comments it? Meaning adds "#" to the first line in a file for example?
Summary: Insert # to the ...
- 06-23-2011 #1Just Joined!
- Join Date
- Dec 2010
- Posts
- 8
Adding # to the first line
Dears,
Does sed or other command edit the 1st line and comments it? Meaning adds "#" to the first line in a file for example?
Summary: Insert # to the first line.
Before: Comment me please.
sed command or another command
After: #Comment me please.
------And if possible a way to remove the "#" using command line.
Thanks.
- 06-23-2011 #2Deleting the # is left as a exerciseCode:
sed '1s/\(.*\)/#\1/' <FILE>
You must always face the curtain with a bow.
- 06-23-2011 #3Just Joined!
- Join Date
- Dec 2010
- Posts
- 8
- 06-23-2011 #4
If you verified the output, then use the -i flag.
sed will then edit in-place.You must always face the curtain with a bow.
- 06-24-2011 #5Just Joined!
- Join Date
- Apr 2011
- Posts
- 2
- 06-24-2011 #6
That is faster and simpler. Nice

Nitpicker: The remove expression should check for the start of the line, aka: "1s/^#//"
Or better yet: optional tabs/whitespaces before the # : "1s/^\([ \t]\)*#//"Last edited by Irithori; 06-24-2011 at 10:00 AM.
You must always face the curtain with a bow.


2Likes
Reply With Quote
