Unix/Linux: Convert fixed-width file to csv and subset on two columns

独自空忆成欢 提交于 2019-12-25 09:59:32

问题


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 }'


来源:https://stackoverflow.com/questions/10102694/unix-linux-convert-fixed-width-file-to-csv-and-subset-on-two-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!