I have a text file "text.txt", it contains a bunch of lines with text (or empty lines).
I am trying to form a single sed/awk command-line command that will let me comment out any like (by adding a "#" to the start of whatever line number I specify).
For example, the text file might look like:
A
B
C
D
and I want to issue a command that specifies line number 2, so it will look like:
A
#B
C
D
If it's possible to specify a range of lines, so multiple lines could be modified, like "2-4" or 2,3,4" that would help, too.
I've found conflicting (to me) information about the -n and -e options in sed, and just can't quite get it to work as I hoped. I'm using Kubuntu 18.04.
Any suggestions? Thanks.
I've been stringing concepts together that I found in other questions, like having to keep the line, but add "#" to the start of it, so I've got "s/(.*)/#$1/" as the back substitution.
I thought it might work as:
sed '2,4!s/(.)/#$1/' text.txt
However, I get s/.: Event not found.
This seemed to have some good parts to it, however, it didn't quite work as I hoped, and it only deals with one line, not all lines cat text.txt | sed -n '2{s/(.)/#$1/;p}'