Parsing the first column of a csv file to a new file

前端 未结 4 936
礼貌的吻别
礼貌的吻别 2020-12-14 14:39

Operating System: OSX Method: From the command line, so using sed, cut, gawk, although preferably no installing modules.

Essentially I am trying to take the first c

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 15:25

    I copy-pasted your sample input, saved it as in.csv, and then ran your first line,

    awk -F"," '{print $1}' in.csv > out.txt
    

    and it worked perfectly, like so:

    $ emacs in.csv
    $ cat in.csv 
    EXAMPLEfoo,60,6
    EXAMPLEbar,30,6
    EXAMPLE1,60,3
    EXAMPLE2,120,6
    EXAMPLE3,60,6
    EXAMPLE4,30,6
    $ awk -F"," '{print $1}' in.csv > out.txt
    $ cat out.txt 
    EXAMPLEfoo
    EXAMPLEbar
    EXAMPLE1
    EXAMPLE2
    EXAMPLE3
    

    This is in Terminal.app on OS X 10.5

提交回复
热议问题