Using a bash script, I'm trying to insert a variable in an awk argument.
!/bin/bash
while read col; do
awk -F'\t' '$22~/$col/' 75437_kbart.txt >> titles.txt
done <col.txt
But I don't get result. The variable "col" is a line in col.txt.
In the command line, I get results :
awk -F'\t' '$22~/EBSCOhost.a9h/' 75437_kbart.txt >> titles.txt
Here, "EBSCOhost.a9h" is a line in col.txt file.
I've read the duplicates. All this does not work :
awk -F'\t' '$22~/$col/' 75437_kbart.txt >> titles.txt
awk -F'\t' '$22~/var/' var="$col" 75437_kbart.txt >> titles.txt
awk -v var="$col" -F'\t' '$22~/var/' 75437_kbart.txt >> titles.txt
awk -F'\t' '$22~/var/' 75437_kbart.txt var="${col}" >> titles.txt
Using the script, I do get a result if I hardcode the $col variable :
awk -F'\t' '$22~/EBSCOhost.a9h/' 75437_kbart.txt >> titles.txt
The "-v" only seems to work with "BEGIN/END".
How can I change the awk argument to include the line of the text file ?
For ex. '$22~/$col/' => '$22~/EBSCOhost.a9h/'