Results 1 to 2 of 2
Thread: How to Uncomment a Single Line
Enjoy an ad free experience by logging in. Not a member yet? Register.
How to Uncomment a Single Line
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.
- Join Date
- Dec 2008
Very simple once you know how to do it