I have a file that is taking in a path as an argument:
./<filename> /path/to/file...
What I want to do is replace the /path/to/… part with /another/file/…
I was trying to sed the argument in the following manner:
CUR_PATH=$1
OLD_PATH="\/path\/to\/"
NEW_PATH="\/another\/file\/"
sed "s/$OLD_PATH/$NEW_PATH/" $CUR_PATH
But this isn’t working because of the fact that sed is trying to actually modify the file at CUR_PATH and not the actual statement of CUR_PATH. How do I fix this? Thanks.
Another possibility is to use a here string:
Also note that you can vary the delimiters for the substitution in sed, so that you don’t have to escape the slashes in your path variables.