Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have just started playing around with text editing using Text Wrangler. I have real estate sales data cut and pasted from a web site on which I have searched and deleted unwanted data and cleaned up the tabs and spaces nicely. However each data record is still split over 2 lines. One line starts with a letter (persons name) and the next starts with an address (a digit). This pattern repeats all the way down the document. How do I say "if line break is followed on next line with a starting digit, replace line break with a tab"

I assume that would put each record on one line ?

share|improve this question
    
Have you tried regular expression matching, combined with the \n line break character? –  user479 Sep 20 '11 at 5:52
    
I guess thats what I'm asking, what is the correct grep pattern. I was using \r (mac) as opposed \n (unix) but neither work. What I think should work is find: \r +[D] replace:\t note i got the example back to front above the first line starts with a digit the 2nd with a letter. –  Visitor82 Sep 20 '11 at 6:04
    
I'm out of my depth with regex, sorry. That's why I didn't post a proper answer! Retag your question with regex and maybe you'll get more love. –  user479 Sep 20 '11 at 6:05
add comment

1 Answer

up vote 1 down vote accepted

I'm assuming you want it like:

Visitor82   123 E. Text Street ...

To do this in Text Wrangler:

  1. Search > Find

  2. Tick the 'Grep' option

  3. In the Find Box type:

    (?(?!\r\d)then)\r

  4. In the Replace Box type (or whatever delimiter you would like):

    \x20

~ Enjoy!

Text Grepping!

share|improve this answer
    
Brilliant ! I had to use D rather than d to represent any non digit character but that worked. Now I will try and work out why ;-) Thanks @ioi –  Visitor82 Sep 20 '11 at 8:29
    
Interesting, \d denotes [digit] and \D [not a digit], so that's got me scratching my head! I'm glad it worked for you; I love Regex, it's language theory and mathematics all rolled into one. ;-) –  l'L'l Sep 20 '11 at 10:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.