I have a pipe-delimited file and I need to grep the first column and if a pattern matched, I will print the whole line. The command below is working but when I put it on a script, I think the $1
is conflicting the command:
Command:
awk -F'|' < filename '{if ($1 == "stringtomatch") print $0}'
Script:
./scripts.sh stringtomatch
Command in script:
awk -F'|' < filename '{if ($1 == "$1") print $0}'
The $1
enclosed in the double quotes is the argument passed to the script. Any advise how to make this work?
arg="$1"; awk -v var="$arg" '{ print var }'
– schrodingerscatcuriosity Sep 25 '20 at 01:53