Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 633
Junba Tester Avatar asked Jul 26 '12 11:07

Junba Tester


People also ask

When opening CSV file all data appears in one column?

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.


1 Answers

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.

like image 172
Levon Avatar answered Sep 22 '22 06:09

Levon