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

前端 未结 4 934
礼貌的吻别
礼貌的吻别 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:30

    If Perl is an option:

    perl -F, -lane 'print $F[0]' in.csv > out.txt

    These command-line options are used:

    • -n loop around every line of the input file
    • -l removes newlines before processing, and adds them back in afterwards
    • -a autosplit mode – split input lines into the @F array. Defaults to splitting on whitespace.
    • -e execute the perl code
    • -F autosplit modifier, in this case splits on ,

    @F is the array of words in each line, indexed starting with $F[0]

提交回复
热议问题