how to cut columns of csv

后端 未结 4 1038
不知归路
不知归路 2021-02-07 03:22

I have a set of csv files (around 250), each having 300 to 500 records. I need to cut 2 or 3 columns from each file and store it to another one. I\'m using ubuntu OS

4条回答
  •  渐次进展
    2021-02-07 03:36

    If your fields contain commas or newlines, you can use a helper program I wrote to allow cut (and other UNIX text processing tools) to properly work with the data.

    https://github.com/dbro/csvquote

    This program finds special characters inside quoted fields, and temporarily replaces them with nonprinting characters which won't confuse the cut program. Then they get restored after cut is done.

    lutz' solution would become:

    csvquote in.csv | cut -d, -f2,3 | csvquote -u 
    

提交回复
热议问题