Highlighted

Grep find/replace to switch Lastname, First M to First M Lastname

Community Beginner ,
Dec 29, 2016

Copy link to clipboard

Copied

I almost have it but have run into a snag that i can't figure out...Hyphenated names

I have to create a index for a directory

I have pulled all the names using "create table of content" from the document that use a certain paragraph style

in the directory they are listed last, first but here they want first, last so i made a find replace using greps that flips them

FIND              ^(\w+), (\w+)([.\w]+)?

REPLACE     $2$3 $1

works fine for Rudy, Scott M

but fails on     Rudy-Goon, Scott M

when it fails it does nothings it would look like the list on the right below after i run it

Rudy, Scott M                 Scott M Rudy

Rudy-Goon,Scott M          Rudy-Goon,Scott M

Doe, John S                    John S Doe

Public, John Q                John Q Public

any suggestions?

thanks in advance!!!!

scott

Try ^([-\w]+), ([-\w+])([-.\w]+)?

Note you have a typo and are missing the space in after the "," in the problematic line, so the above grep won't work either unless you add the space.

HTH

Trevor

TOPICS
Scripting

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Grep find/replace to switch Lastname, First M to First M Lastname

Community Beginner ,
Dec 29, 2016

Copy link to clipboard

Copied

I almost have it but have run into a snag that i can't figure out...Hyphenated names

I have to create a index for a directory

I have pulled all the names using "create table of content" from the document that use a certain paragraph style

in the directory they are listed last, first but here they want first, last so i made a find replace using greps that flips them

FIND              ^(\w+), (\w+)([.\w]+)?

REPLACE     $2$3 $1

works fine for Rudy, Scott M

but fails on     Rudy-Goon, Scott M

when it fails it does nothings it would look like the list on the right below after i run it

Rudy, Scott M                 Scott M Rudy

Rudy-Goon,Scott M          Rudy-Goon,Scott M

Doe, John S                    John S Doe

Public, John Q                John Q Public

any suggestions?

thanks in advance!!!!

scott

Try ^([-\w]+), ([-\w+])([-.\w]+)?

Note you have a typo and are missing the space in after the "," in the problematic line, so the above grep won't work either unless you add the space.

HTH

Trevor

TOPICS
Scripting

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 29, 2016 0
Guru ,
Dec 29, 2016

Copy link to clipboard

Copied

Try ^([-\w]+), ([-\w+])([-.\w]+)?

Note you have a typo and are missing the space in after the "," in the problematic line, so the above grep won't work either unless you add the space.

HTH

Trevor

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2016 0
Explorer ,
Dec 30, 2016

Copy link to clipboard

Copied

Maybe this one helps you:

find: ^((\w+)(-\w+)?), ?(\w+ \w)

change to: $4 $1

I've added " ?" after comma if this kind of typos that Trevor mentioned are more frequent.

Cheers,jf

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2016 0
Mentor ,
Dec 30, 2016

Copy link to clipboard

Copied

Just another approach...

names.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2016 1
Community Beginner ,
Dec 30, 2016

Copy link to clipboard

Copied

Thank you all for the help...You all make it look so easy to do this and it seems so obvious AFTER i see the answer--like a good riddle

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2016 0
New Here ,
May 13, 2020

Copy link to clipboard

Copied

Wonderful!!!!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 13, 2020 0
New Here ,
May 22, 2020

Copy link to clipboard

Copied

Does anyone know how to change firstname_lastname to lastname, firstname?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 22, 2020 0
New Here ,
May 22, 2020

Copy link to clipboard

Copied

Does anyone know how to change firstname_lastname to lastname, firstname?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 22, 2020 0
Most Valuable Participant ,
May 22, 2020

Copy link to clipboard

Copied

That would be

Find: (.+?)_(.+)

Change to: $2, $1

 

If this does not work for you, post a new question and include examples.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 22, 2020 0