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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 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.
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:
I just want to write
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:
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:
sed -re '5 s/^#//' file
I hope that this answers the question.
- 02-15-2010 #2
- Join Date
- Dec 2008
Very simple once you know how to do it