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

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

Explorer ,
Dec 29, 2016 Dec 29, 2016

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
2.5K
Translate
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

Translate
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

Translate
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

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

Translate
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

Just another approach...

names.png

Translate
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

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

Translate
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

Wonderful!!!!

Translate
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

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

Translate
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

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

Translate
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

That would be

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

Change to: $2, $1

 

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

Translate
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

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

Translate
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
LATEST

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

Translate
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