0

My code is

ip=$(awk -F, "IGNORECASE = 1; $4 ~ /$line/ {print $4}"  $today-combined.csv | wc -l)
html=$(awk -F, "IGNORECASE = 1; $5 ~ /$line/ {print $5}"  $today-combined.csv | wc -l)

when i do sh -x test.sh , i got this

++ awk -F, 'IGNORECASE = 1;  ~ /eg/ {print }' 2021-01-16-combined.csv
++ wc -l
awk: cmd. line:1: IGNORECASE = 1;  ~ /eg/ {print }
awk: cmd. line:1:                  ^ syntax error
+ ip=0
++ awk -F, 'IGNORECASE = 1;  ~ /eg/ {print }' 2021-01-16-combined.csv
++ wc -l
awk: cmd. line:1: IGNORECASE = 1;  ~ /eg/ {print }
awk: cmd. line:1:                  ^ syntax error
+ html=0

I am not sure where I am getting a syntax error.

I try that also

ip=$(awk -F, 'IGNORECASE = 1; $4 ~ /$line/ {print $4}'  $today-combined.csv | wc -l)
html=$(awk -F, 'IGNORECASE = 1; $5 ~ /$line/ {print $5}'  $today-combined.csv | wc -l)

but it wont pick $line value.

I try / before ' but no result for that too.

Any help?

Amit
  • 57
  • 5
  • You can so `"balbla"'blabla'"blabla"`. Like `'IGNORECASE = 1; $4 ~ /'"$line"'/ {print $4}'`. But it's __way__ better to do `awk -v line="$line" -F, '$4 ~ line{print $4}'` and still, it's way better to do read the file _once_ for speed, like `read -r ip html < <(awk -F, -v line="$line" 'IGNORECASE = 1; $4 ~ line{a++} $5 ~ line{b++} END{ print a, b}' "$today-combined.csv")`. You do not need `wc -l`. – KamilCuk Jan 16 '21 at 13:30
  • Consider putting `IGNORECASE = 1` into a BEGIN block too. – oguz ismail Jan 16 '21 at 13:32

0 Answers0