regex - awk: parse columns like: [1,2,3] in csv file -
i have csv file looks so:
a, b, c 1, 2, [1, 2, 3] 4, 5, [7, 7, 7, 7, 8] 5, 3, [] 6, 5, [45, 45, 2, 1, 2, 8, 8]
i extract third column via awk
, me means telling awk
field separator comma not inside pair of brackets. extract:
c 1,2,3 7, 7, 7, 7, 8 4, 4, 2, 1, 2, 8, 8
i tried using regular expression set fs field separator
on ubuntu command line:
awk '{fs = ["^\[],[^\]]"} {print $3}' file.csv
but printed out:
c [ [ [] [4
which not close like. problem how defining field separator or have done else wrong well? input.
you can use pattern field separator:
awk -f '^[^,]*,[^,]*, [[]?|]' '{print $2}'
Comments
Post a Comment