Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP f/c switch names and states

Tagged: 

Return to Member Forum

  • Author
    Posts
    • #66717
      Cindy Kelley
      Participant

      I have

      Tom Jones, Nevada
      Madonna, New York
      Mary Louise Parker, California
      Al Roker, New York

      and I need

      Nevada: Tom Jones
      New York: Madonna, Al Roker
      California: Mary Louise Parker

      I have come up

      ^(\w+ \w+ \w+), (\w+ )
      $2: $1,

      For you grep experts you can see that I have set to find names with three words and a comma and then a word of just one word. This will work in finding those but then I will need to adapt for names with two words and states with two words.

      I haven’t figured out the and/or function of grep so I am sure I am doing this the hard way and would like to learn.

      I also figure I may have to end up with

      Nevada: Tom Jones
      New York: Madonna
      California: Mary Louise Parker
      New York: Al Roker

      but then I can sort alphabetically and delete the duplicated states.

      Any help in my learning is appreciated. :)

      Happy Saturday!
      Cindy in (snowy) Indy

    • #66785
      Erica Gamet
      Participant

      I adapted from another GREP search I have. This fits your example (actually, I made one Tom S. Jones to be sure an initial would work).
      find:
      ^(\w+)([ \w.]+)?(\w+)?(,)( )(.+)
      change to:
      $6: $1$2$3
      I don’t think I could make it group all New York listings together, for example.

    • #66797
      Cindy Kelley
      Participant

      Thanks Ekwoman!

      I will give it a try. It should save me a lot of time.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
Forum Ads