How can I add a variable within awk command? below is my command:
cat /home/ubuntu/test/copy.txt | awk 'NR==21{print ".host = "$line";"}1'
$line is basically an IP address which is retrieved from a text file. With the above command the output looks like
.host = ;
Any immediate help would be really appreciated.
Format of copy.txt
backend default {
#.host = value; need to be here
.port = "8080";
}
The variables in
awk
can be transferred from shell on this way:and used inside on this way:
The variable should be set beforehand in bash so the things become:
Also you do not need
cat
, just use this way:To store the output in a file you should use something like:
and the result will be stored in
/home/ubuntu/test/new_copy.txt