I have written a bash script (File.sh) to change the third column of a file (File.txt) with a particular string (NULL).
File.txt -
abc def 123
qwe gfh 456
File.sh -
#!/bin/bash
FILE1='file.txt'
while IFS= read -r line
do
awk '$3= "NULL"' file.txt > tmp.txt && mv tmp.txt file.txt
done <"$FILE1"
and this works fine.
output
abc def NULL
qwe gfh NULL
But now I'am trying to update the third column using a variable instead of a text-
var='NULL'
awk '$3= $var' file.txt > tmp.txt && mv tmp.txt file.txt
this doesn't work. what can be the mistake in syntax.