Hello
I've a text file with a line
default_color acolor
and I want to replace this line with
default_color anothercolor
I don't know the first color and the second is contained in a variable. How can I do it in bash ?
Thank you
Hello
I've a text file with a line
default_color acolor
and I want to replace this line with
default_color anothercolor
I don't know the first color and the second is contained in a variable. How can I do it in bash ?
Thank you
It is not pure bash but if you have other console tools, try something like
cat your_file | sed "s/default_color\ .*/default_color\ $VAR/"
You could use awk. The manual entry is here:
I won't write the regular expression necessary, as that will depend on your color format, but this will fit the bill. Best of luck.
use gawk
awk '$2=="defaultcolor"{$2="anothercolor"}1' file
or just bash shell and no external commands
while read -r line
do
case "$line" in
*defaultcolor*) line=${line/defaultcolor/anothercolor}
esac
echo $line
done <"file"
Not really a bash solution, but you can do the replacement in-place, for any number of files, with perl:
perl -i -npe 's/default_color acolor/default_color another_color/' list_of_files