• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Dec 29, 2016 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

TOPICS
Scripting

Views

2.1K

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
community guidelines

correct answers 1 Correct answer

Guru , Dec 29, 2016 Dec 29, 2016

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

Votes

Translate

Translate
Guru ,
Dec 29, 2016 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

Votes

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
community guidelines
Explorer ,
Dec 30, 2016 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

Votes

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
community guidelines
Mentor ,
Dec 30, 2016 Dec 30, 2016

Copy link to clipboard

Copied

Just another approach...

names.png

Votes

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
community guidelines
Explorer ,
Dec 30, 2016 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

Votes

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
community guidelines
New Here ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

Wonderful!!!!

Votes

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
community guidelines
New Here ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
New Here ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
May 22, 2020 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.

Votes

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
community guidelines
New Here ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

How do you change lastname, firstname to firstname lastname
None of the above are helping me?

Votes

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
community guidelines
Community Expert ,
Aug 21, 2023 Aug 21, 2023

Copy link to clipboard

Copied

LATEST

winterm's reponse of 30 Dec. 2016 should do it. Did you try that one?

Votes

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
community guidelines