copy/paste every shell script you write into http://shellcheck.net and fix the issues it tells you about until you learn the basics and certainly before posting a question containing such a script on this forum. It's frustrating to us when people post scripts that contain errors that a tool can detect.
In addition to the errors shellcheck will tell you about - you don't need cat
or sed
when you're using awk
and sort | uniq
= sort -u
but in any case your whole pipeline could be reduced to one awk script:
exist=$( awk -F, '(NR>1) && ($4 !~ /^(999?\.){3}999?$/) && !seen[$1]++{cnt++} END{print cnt+0} Test.csv)' )
Also see Correct Bash and shell script variable capitalization for why I'm using exist
instead of EXIST
as the variable name.
The fact you're storing that count of unique $1
s in a variable named exist
, though, makes me wonder if you really need it to hold a count at all.