Need GREP to reorder a list of names

26 views
Skip to first unread message

Howard

unread,
Feb 3, 2022, 8:12:54 PM2/3/22
to BBEdit Talk
Here is a sample of the data I have in a column:
Guerrero Jr., Vladimir
Perez, Salvador
Machado, Manny
Bichette, Bo
Goldschmidt, Paul
Devers, Rafael
Judge, Aaron
Freeman, Freddie

Desired output
For each name, I need all the characters after each comma moved to the start of the name followed by a space and the comma removed so that the names appear this way:
Vladimir Guerrero Jr.
Salvador Perez
Manny Machado
Bo Bichette
Paul Goldschmidt
Rafael Devers
Aaron Judge
Freddie Freeman 


Thanks in advance for any help you can provide,
Howard

ThePorgie

unread,
Feb 3, 2022, 8:50:37 PM2/3/22
to BBEdit Talk
Find:
([^,\r]+), (.+)
Replace:
\2 \1

([^,\r]+)//finds everything but a comma or return
, //finds the comma space
(.+)//finds everything after the comma space
//Parentheses capture the two groups

\2 //Replace with found group 2 follow by a space
\1//Replace with found group 1

jj

unread,
Feb 4, 2022, 2:55:28 AM2/4/22
to BBEdit Talk
Hi Howard,

BBEdit has a nice option to help rearrange columns in CSV files:

        BBEdit > menu Edit > Columns > Rearrange Columns…
       
Once the columns are in the desired order, if required you can remove the commas with a find/replace.

HTH

Jean Jourdain
Reply all
Reply to author
Forward
0 new messages