I wanted to comment out a few lines in a config file. This was a result of getting to single user mode on a Tru64 box, because some SCSI drives had gone missing!
Anyway Sed to to the rescue! How do I look for a string then comment out that entire line? Not beign that familar with SED I struggled but:
sed 's/.*sda6.*/#&/g' test
The “&” means the entire match, so “#&” means comment out that line! Trying to match the entire line did confuse me, as trying to use a wildcard gave me errors. Until it dawned on me… “*” means “more than one of the previous character. so “.*” means more than one of any character i.e. wildcard!
I’ve since been told that there’s a far easier way of doing this. e.g. using the “find” function then an upper case “I”nsert, which means insert at the beginning og a line, rather than at the current location in the buffer.
2 Replies to “useful SED line”
Ha! This is just what I was looking for. I was trying:
sed -i -e ‘s`^output database*mysql*`#`g’ …
And couldn’t figure out why it wasn’t working. Nice job.
Comments are closed.