Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How may I apply double quotes around every value of csv file using TextMate?

I have a csv file with the following format:

example csv:

bear,brown,mean,large
ant,black,strong,tiny
cat,yellow,moody,small

How may I apply double quotes around every value? How may I accomplish this using regex?

I am using TextMate (text editor) to do the find/replace w/ regular expression.

like image 632
Brad Avatar asked Aug 24 '10 19:08

Brad


2 Answers

Here are the important portions of the regex. Hopefully I got it right when I converted to textmate format:

Search - ([^,]*)(,|$)

Replace - "$1"$2

Search explanation: Find every character that is not a comma, up until we reach a comma, or the end of the line. Capture the match for string to be quoted in one variable, and capture the comma/end-of-line match in another variable.

Replace explanation: The original string, quoted, and the comma or end-of-line that follows it.

like image 146
Merlyn Morgan-Graham Avatar answered Oct 26 '22 11:10

Merlyn Morgan-Graham


You could start with:

find: ,
replace: "," 

then add a " at the start and at the end?

like image 27
nicomen Avatar answered Oct 26 '22 10:10

nicomen