how to cut columns of csv

后端 未结 4 1036
不知归路
不知归路 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:23

    If you used ssconvert to get the CSV you might try:

    ssconvert -O 'separator="|"' "file.xls" "file.txt"
    

    Notice the TXT extension instead CSV, this way will use Gnumeric_stf:stf_assistant exporter instead of Gnumeric_stf:stf_csv, which let you use options (-O parameter). Otherwise you'll get a The file saver does not take options error. Pipe character is much more unlikely, but you might want to check before.

    Then you can rename it and do things like:

    cat file.csv | cut -d "|" -f3 | sort | uniq -c | sort -rn | head
    
    • Other options example: -O 'eol=unix separator=; format=preserve charset=UTF-8 locale=en_US transliterate-mode=transliterate quoting-mode=never'.
    • A solution with AWK v4+.
    • ssconvert man page.

提交回复
热议问题