1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Help With Find and Replace

Discussion in 'General Software' started by TIGR, Jan 16, 2011.

  1. TIGR

    Joined:
    Aug 17, 2008
    Messages:
    2,183 (1.06/day)
    Thanks Received:
    1,029
    Location:
    Minnesota, USA
    Real basic question for anyone with experience.

    I have a long list of cities and zip codes formatted in the following way:

    55472 Abmps
    56510 Ada


    I need to replace the space between each zip code and its city with a comma, as such:

    55472,Abmps
    56510,Ada


    In the Find and replace dialog, next to find I am using [0-9] [A-Z] to find all instances of a number followed by a space followed by a capital letter. This finds everything I need it to.

    But then I intuitively tried, next to replace, using [0-9],[A-Z] and it results in this:

    5547[0-9],[A-Z]bmps
    5651[0-9],[A-Z]da


    How can I tell Notepad++ to leave the zip and city alone while changing the space?
  2. scaminatrix

    scaminatrix

    Joined:
    Mar 1, 2010
    Messages:
    3,576 (2.37/day)
    Thanks Received:
    787
    Location:
    By the Channel Tunnel, Kent, England
    There may be a trick you can try:
    does the "space" have an Alt code? Like "enter" key combination is Alt+0013.
    If you could tell it to find and replace using the Alt code's, that may work.


    EDIT:
    Space = Alt+32
    Comma = Alt+44
    TIGR says thanks.
  3. TIGR

    Joined:
    Aug 17, 2008
    Messages:
    2,183 (1.06/day)
    Thanks Received:
    1,029
    Location:
    Minnesota, USA
    I can actually just type in a space next to "find" and that will find all the spaces. The problem with that is that some of the city names are more than a single word. For example "St. Paul".
    scaminatrix says thanks.
  4. scaminatrix

    scaminatrix

    Joined:
    Mar 1, 2010
    Messages:
    3,576 (2.37/day)
    Thanks Received:
    787
    Location:
    By the Channel Tunnel, Kent, England
    Now that's tricky!
    Ok, try this. It's long winded as you'll have to repeat the action 10 times.

    Find "0 " and replace with "0," then repeat with other numbers.
    "9 " "8 " etc.

    EDIT: Unless some of the place names have numbers, it should work. Might have to use the Alt codes still.

    2ND EDIT: Just read the OP again, if you find "[0-9] [A-Z]" and replace with "," instead of replacing with "[0-9],[A-Z]", does that do anything different?
    Last edited: Jan 16, 2011
    TIGR says thanks.
  5. TIGR

    Joined:
    Aug 17, 2008
    Messages:
    2,183 (1.06/day)
    Thanks Received:
    1,029
    Location:
    Minnesota, USA
    That'll get me through this job just fine. I know there's a basic "proper" way of doing this with regex and hope someone will chime in with it for future reference later, but for now I need to get this done.

    Thank you much scaminatrix. :toast:
    drdaver, coljarcker and scaminatrix say thanks.
  6. scaminatrix

    scaminatrix

    Joined:
    Mar 1, 2010
    Messages:
    3,576 (2.37/day)
    Thanks Received:
    787
    Location:
    By the Channel Tunnel, Kent, England
    That's alright mate, which way did you use, the long winded way?
  7. TIGR

    Joined:
    Aug 17, 2008
    Messages:
    2,183 (1.06/day)
    Thanks Received:
    1,029
    Location:
    Minnesota, USA
    I did it the "long winded way" although really that only took a minute anyway haha so that was just fine.. If I replace [0-9 [A-Z] with just a comma, the comma ends up replacing not only the space but also the last number of each zip and the first letter of each city.
    drdaver, coljarcker and scaminatrix say thanks.
  8. W1zzard

    W1zzard Administrator Staff Member

    Joined:
    May 14, 2004
    Messages:
    14,544 (4.01/day)
    Thanks Received:
    11,216
    grab ultraedit and use the regexp search and replace
    danik and TIGR say thanks.
  9. TIGR

    Joined:
    Aug 17, 2008
    Messages:
    2,183 (1.06/day)
    Thanks Received:
    1,029
    Location:
    Minnesota, USA
    Thanks W1zzard, trying that out now.
  10. PopcornMachine

    PopcornMachine

    Joined:
    Aug 17, 2009
    Messages:
    1,561 (0.92/day)
    Thanks Received:
    458
    Location:
    Los Angeles/Orange County CA
    Using perl, if the 2 fields are separated by one or more spaces, then

    perl -n -e 's/\s+/,/;print' file > newfile
    Last edited: Jan 18, 2011
    TIGR says thanks.
  11. Easy Rhino

    Easy Rhino Linux Advocate

    Joined:
    Nov 13, 2006
    Messages:
    13,197 (4.87/day)
    Thanks Received:
    3,122
    any decent text editor should make it easy for you to find/replace

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page