Awk Variable Value from Bash
Suppose you have a bash script that wants to pass a value to an awk line. You would do something like this:
1awk -v today="$(date)" 'BEGIN {print today}'
Key above is the -v in awk which can be repeated as there are variables to assign. See man awk for details.
If you put it into the awk body, (outside BEGIN), you need to terminate it with <<</dev/null. Otherwise, it will wait for indefinite input.
1#!/bin/bash
2
3this=$1
4
5awk -v bash_this="$this" '{print "Given by bash: " bash_this}' <<</dev/null
sample output of above script:
1~$ ./bash_input_to_awk.bash here
2Given by bash: here
CREDITS: https://www.cyberciti.biz/faq/linux-unix-appleosx-bsd-bash-passing-variables-to-awk/