Hi, Im trying to get current line in the AGREP command I use in AWK. My script looks like this:
list.txt
car
bus
checklist.txt
cer
buss
cat list.txt | awk -v mycmd="$(agrep -2 -i $0 checklist.txt)" '{print $mycmd}'
It doesnt work. How can I get the current line in the $0 variable? Or is there any different solution? I need to go through each line in list.txt, search & compare it in checklist.txt and get a result.
Not just any awk uses variables. Use gawk or nawk if available. Otherwise use your inline function embedded as you have above; you'll just need to escape it, or wrap it within an eval statement.
As per the man awk (linux) manpage:OPTIONS
Gawk accepts the following options:
-v var=val
--assign var=val
Assign the value val to the variable var, before execution of the program begins. Such variable values are available to the BEGIN block of an AWK program.
For example: