awk passing in a parameter using solaris / sunos

 

take this file , new_list.csv and you wish to see only column 2 with values 14

Tokyo1,3
Tokyo1,3
Tokyo1,3
Tokyo1,3
Tokyo1,3
Tokyo1,3
Tokyo1,3
LONDON1,14

LONDON2,14
LONDON3,14
LONDON4,14
LONDON5,14
LONDON6,14
PARIS1,14
PARIS2,14
PARIS3,14

 

count=14

Using Solaris

awk -vcount=$count -F"," ' ( $2 == '"$count"' )  { print $1 }' new_list.csv
 

 

outputs these values

LONDON1,14
LONDON2,14
LONDON3,14
LONDON4,14
LONDON5,14
LONDON6,14
PARIS1,14
PARIS2,14
PARIS3,14

 

Using Linux , use without quotes around the variable count. like below;

awk -vcount=$count -F"," ' ( $2 == count )  { print $1 }' new_list.csv