I am writing a shell script to be able to append text after the match is found in a file
for example, in ~/.bash_profile file for the following line
PATH=$PATH:$HOME/bin
we need to append it with :/usr/java/jdk1.6.0_38/bin
so it’ll become the following
PATH=$PATH:$HOME/bin:/usr/java/jdk1.6.0_38/bin
how could I do it with sed?
I tried with the following command from inside the console first, but it gave me error complaining ‘sed: -e expression #1, char 13: unknown option to `s”
sed '/PATH/s/$/:/usr/java/jdk1.6.0_38/bin' ~/.bash_profile
what’s wrong with my command above?
The problem is that you have regex delimiters in the replacement part of the substitute command. Either escape them with
\or use a different delimiter (comma in this case):