I wrote the following command:
var=$(printf "$line" | awk -F':' {'print $2'} | sed 's/,//g')
sed -i "s/$var/exampletext/g" "file.txt"
The text is part of a larger script that finds a specific value, and then replaces it with another value.
The basic end result I want is something like this:
sed -i "s/123/exampletext/g" "file.txt"
That should replace all of the 123
's in file.txt with exampletext
. When I echo $var
, it shows the result of 123
. Yet when that command is run, it doesn't work - it does not replace 123
with exampletext
.
Here is the full script:
INPUT="$1"
while IFS= read -r line;
do
if [[ $line == *"length"* ]];
then
var=$(printf "$line" | awk -F':' {'print $2'} | sed 's/,//g')
sed -i "s|$var|cookiecrisp|g" "vomit.txt"
fi
done < $INPUT