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.
When you open it in your spreadsheet editor (Excel, for example), it shows all of the data in a single column, instead of splitting them across columns. The reason behind this behavior is that CSV files (Comma Separated Values) are splitting data into columns using " , " as separator by default.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With