Results 1 to 2 of 2
I received this PM from another forum user. I am a strong believer in answering questions on the forum itself, so I will answer it here.
Hi,
I've been trying ...
- 02-12-2010 #1
How to Uncomment a Single Line
I received this PM from another forum user. I am a strong believer in answering questions on the forum itself, so I will answer it here.
The basic format of what you said is correct, but grep is unnecessary here. sed is capable of finding lines on its own.Hi,
I've been trying to do something with sed and I can't figure it out. By reading the posts, your understanding of sed is light years ahead of me and I hope you can help me.
I'm trying to use sed inline sed -i to find a specific line in a file and remove the first character which is a #. Yes just find a line and uncomment it.
Say I have:
#hello
I just want to write
hello
in the same spot in the file
I have found other ways of doing it like grep'ing for the line and running it thru sed to strip the comment but I'm sure there is a more elegant way of doing it.
If we assume that the line has a particular pattern, it is very simple:
This takes any line that matches PATTERN, and replaces the '#' at the beginning of the line with nothing, essentially deleting the line.Code:sed -re '/PATTERN/ s/^#//' file
On the other hand, if there is no pattern, but it is a particular line number, it is even easier:
This takes line 5 and removes the '#' at the beginning.Code:sed -re '5 s/^#//' file
I hope that this answers the question.DISTRO=Arch
Registered Linux User #388732
- 02-15-2010 #2Just Joined!
- Join Date
- Dec 2008
- Posts
- 7
Thank you.
Very simple once you know how to do it


Reply With Quote