fahrradlaus
fahrradlaus

Reputation: 197

Filter csv list with awk

I have the following (much longer) csv list:

...
"AT3";"AT32";"AT322";"504";"50401"
"AT2";"AT13";"AT322";"504";"50401"
"AT2";"AT13";"AT31243";"604";"503401"
...

Now, I'd like to filter all rows which contain "AT13" in the 2nd column.

I tried: awk 'BEGIN {FS=","} {if($2 == "AT13") print}' GISA-OpenData.csv > WIEN.csv But it doesn't give my any output. Does anyone know what could be the error here? WIEN.csv is always empty.

many thanks

Upvotes: 0

Views: 356

Answers (1)

JNevill
JNevill

Reputation: 50034

You can use:

awk -F";" '$2=="\"AT13\""' GISA-OpenData.csv > WIEN.csv

Since your field seperator (FS) is just a comma, you have to search when $2 has the value you want surrounded by double quotes, which we escape here.

You could also do a regex like search so you don't have to monkey with escaping:

awk -F";" '$2~"AT13"' GISA-OpenData.csv > WIEN.csv

Upvotes: 1

Related Questions