convert a fixed width file from text to csv

后端 未结 4 2017
梦谈多话
梦谈多话 2021-02-01 09:59

I have a large data file in text format and I want to convert it to csv by specifying each column length.

number of columns = 5

column length

[4          


        
4条回答
  •  臣服心动
    2021-02-01 10:35

    GNU awk (gawk) supports this directly with FIELDWIDTHS, e.g.:

    gawk '$1=$1' FIELDWIDTHS='4 2 5 1 1' OFS=, infile
    

    Output:

    aasd,fh,90135,1,2
    ajsh,dj, 2445,d,f
    

提交回复
热议问题