I’m using a sed command for replacing some words in text files. This command is embedded in a ksh script.
I would like to reach that not everytime will every replacement rule of sed fire, only if some conditions are filled. E.g. depending on a value of a shell variable.
In other words I would like to write this script without the if statement, I would rather include the conditional expression inside the sed. Is it possible?
REPLACE_A=TRUE
if [ "$REPLACE_A" = "TRUE" ]
then
cat myfile \
| sed 's/A/B/g;
's/C/D/g;
's/E/F/g;'
else
cat myfile \
| sed 's/C/D/g;
's/E/F/g;'
fi
The only solution that pops into my mind is to store the
sedcommand in a variable, likeBut it still not the solution you want.