Results 1 to 6 of 6
Thread: Adding # to the first line
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
06-23-2011 #1
- Join Date
- Dec 2010
- Posts
- 10
Adding # to the first line
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 #2Code:
sed '1s/\(.*\)/#\1/' <FILE>
You must always face the curtain with a bow.
-
06-23-2011 #3
- Join Date
- Dec 2010
- Posts
- 10
-
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 #5
- 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.