Help in deleting columns in a CSV file.

17 views
Skip to first unread message

tchamba junias

unread,
Feb 6, 2018, 10:23:44 PM2/6/18
to TextWrangler Talk
Hi, 
I downloaded a dataset from the internet in a CSV file format. I've tried to delete columns but each attempt results in the whole data in the spreadsheet to disappear. The columns of interest are the scientific name, the decimal longitude, and the decimal latitude. I don't know how to deal with that. I would greatly appreciate any helping hand in solving this issue.
 
csv_file_to_clean.csv

Kendall Conrad

unread,
Feb 8, 2018, 10:29:16 PM2/8/18
to TextWrangler Talk
Well, the file isn't a true CSV format. Each line/row is surrounded by double quotes, which would technically make it a one column file. Within each line is tab delimited instead of commas. So that makes some solutions not work as is.

If you only need to do this once then I'd simply open the file in a spreadsheet application like Excel or LibreOffice and just delete the columns and be done with it. If you need to do this programmatically then I'd start by deleting the quotes at the start and end of each line. You listed columns of interest, but I wasn't sure if those were columns you want to delete or the columns you want remaining after deleting the rest.

If you want to delete column 3 then you could do:

find: ^([\w-]+\t){2}[\w:\.-]+\t(.*)$
replace with: \1\2

-Kendall
Reply all
Reply to author
Forward
0 new messages