A simple way to use sed
to comment on the lines that match a certain pattern is to "select" those lines with a regular expression, and "apply" the substitution of the "start of line" with the character #
. That is:
sed '/expresion-regular/s/^/#/g' < entrada > salida
The "quiz" here is the regular expression that you should use, and what version of sed
uses as the details of the syntax vary between versions.
The regular expression can be as simple as a word, but in this case it seems that there are two that you are looking for. A regular expression like the following will select the lines that begin with "$InputFileName"
or "$InputFileTag"
:
/^(\$InputFileName|\$InputFileTag)/
In fact, since both chains start the same, you can also put it like this:
/^\$InputFile(Name|Tag)/
Notice that the $
must have a \
in front to "escape" its special meaning in a regular expression.
Now, to use that regular expression in sed
, you have to add some extra characters depending on what version of sed
uses:
-
GNU sed (It's the version that comes on Linux)
In this version you must also escape the parentheses and the |
, so you should use:
sed '/^\$InputFile\(Name\|Tag\)/s/^/#/g' < entrada > salida
-
BSD sed (it's the version that comes on OSX)
In this version there is no need to escape parentheses, and the |
does not understand it by default, but it will admit it if you add the option -E
. Therefore:
sed -E '/^\$InputFile(Name|Tag)/s/^/#/g' < entrada > salida
Once you have checked (looking at the file salida
) that has worked correctly, you can change the syntax for this one, to directly modify the input file:
sed -i '..lo_antes_dicho...' entrada