Unix/Linux: Convert fixed-width file to csv and su

2019-09-07 21:26发布

问题:

I have this fixed-width file with the widths being 34, 2, 3, 2, 1, 1, 3, 1, 2, 1, 2, 2 and 75 which I want to (a) convert to delimited (csv) format and then (b) subset according to V2="03" and V5="1". I have figured out the first step:

awk -v FIELDWIDTHS='34 2 3 2 1 1 3 1 2 1 2 2 75' -v OFS=',' '{ $1=$1 ""; print }' </filepath/Parse.txt > /filepath/Parse.csv

But I am stumped at step 2.

回答1:

Try with:

awk -v FIELDWIDTHS='...' -v OFS=',' '($2=="03") && ($5=="1"){ $1=$1 ""; print }'


标签: unix subset