How to get the first column of every line from a CSV file?
问题 How do get the first column of every line in an input CSV file and output to a new file? I am thinking using awk but not sure how. 回答1: Try this: awk -F"," '{print $1}' data.txt It will split each input line in the file data.txt into different fields based on , character (as specified with the -F ) and print the first field (column) to stdout. 回答2: Can be done: $ cut -d, -f1 data.txt 回答3: echo "a,b,c" | cut -d',' -f1 > newFile 回答4: Input a,12,34 b,23,56 Code awk -F "," '{print $1}' Input