Extract data based on 2nd colume having double quotes

i want extract where the 2nd column having "3" or "7".
Based on the forums tried like this but it is not working

awk -F"," '$2=3;$2=7 {print}' filename
Source 
"1","2","3","4"
"1","3","3","4"
"1","7","3","4"
"1","8","3","4"
"1","2","3","4"
"1","2","3","4"

Output :


"1","3","3","4"
"1","7","3","4"

Thanks

  • Onesuri
$ awk -F"," -v qt='"' '$2==qt 3 qt || $2==qt 7 qt ' file
"1","3","3","4"
"1","7","3","4"
awk -F, '$2~/"(3|7)"/' file
"1","3","3","4"
"1","7","3","4"
awk -F, '$2~/"3"|"7"/' file
awk -F, '$2~/"[37]"/' file
awk -F, '$2=="\"3\"" || $2=="\"7\""' file

or

awk -F'",?"?' '$3==3||$3==7' file

or

awk -F\" '$4==3||$4==7' file

--
@Jotne, that should be /"(3|7)"/ or /"[37]"/ for your first and your last option, no?

1 Like
awk -F '","' '$2==3 || $2==7' file

OR

egrep '^.....(3|7)"' file

Yes, it will pick wrong if number is larger(more numbers), corrected

Some more variation
awk -F, '{split($2,a,"\"")} a[2]==3 || a[2]==7'

@pamu
awk -F '","' '$2==3 || $2==7' file
Is not a good option if you later like first or last field.