If I've understood correctly, you want to use $1
from your shell script as an argument to the awk
command within it.
In which case, you want to not quote the $1
that you want expanding, but do quote the rest of the awk
command. One possibility is to double-quote the command:
awk "{if (\$1 == \"$1\") printf(\"%s_%s_%s \\t%s\\n\", \$1,\$2,\$3,\$4);}"
It can get hard to manage all the backslashes, so you probably prefer to single-quote most of the command, but double-quote the part to be expanded:
awk '{if ($1 == "'"$1"'") printf("%s_%s_%s \t%s\n", $1,$2,$3,$4);}'
That's slightly tricky to read - the critical bit divides as '...($1 == "'
"$1"
'")...'
. So there's a double-quote that's part of the Awk command, and one that's for the shell, to keep $1
in one piece.
Oh, and no need to invoke cat
- just provide the file as input:
awk ... <result_file >file.txt