Can someone help me with this bash command please:
sed -i "s/\$CORPUS_DATA/$CORPUS_DATA/g" conf/*.xml
What does it mean?
Can someone help me with this bash command please:
sed -i "s/\$CORPUS_DATA/$CORPUS_DATA/g" conf/*.xml
What does it mean?
It replaces the value of the text "$CORPUS_DATA" in the file, to the actual value of the environment variable $CORPUS_DATA
.
Test it:
$ CORPUS_DATA=hello
$ echo '$CORPUS_DATA'
$ $CORPUS_DATA
$ echo '$CORPUS_DATA' | sed "s/\$CORPUS_DATA/$CORPUS_DATA/g"
hello
Note that the first part escapes the $
sign, so the regex will match the text "$CORPUS_DATA" literally. The second part doesn't, which means it takes the value of the env variable.
Following is the explanation of code.
sed -i "s/\$CORPUS_DATA/$CORPUS_DATA/g" conf/*.xml
-i
is for saving the output into Input_file itself.
s
using substitute option changing \$CORPUS_DATA
with shell variable $CORPUS_DATA
value.
g
means do this change to all occurrences in current line.
conf/*.xml
loop through all xml files in conf directory.