useful SED line

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

Works nicely!!

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!

Cool!

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.