0

I've got some sloppy text that needs to be cleaned up. Somehow random line breaks got inserted in the middle of paragraphs.

This is a paragraph
and it got broken into two lines.

The manual way to deal with this would be to

  1. Place my cursor at the beginning of line 2
  2. Hit delete to bring that line up to line 1
  3. Hit space to separate the two words that get mashed together by doing this

Is there a way to accomplish this with Find and Replace? I know I can find the offending lines with ^[a-z] and checking "Case Sensitive", but that's as far as I can get.

I'm just starting to learn how powerful pattern matching can be and I've solved all the other cleanup issues, but this one still perplexes me.

Tomulent
  • 531
  • 2
  • 5
  • 20

2 Answers2

0

Using awk in linux

cat file
This is a paragraph
and it got broken into two lines.
This line is fine and should be printed.
Here is another
that has been broken.

awk 'NR>1 {printf "%s"(substr($0,1,1)~/^[[:lower:]]$/?FS:RS),a} {a=$0} END {print a}' file
This is a paragraph and it got broken into two lines.
This line is fine and should be printed.
Here is another that has been broken.
Jotne
  • 40,548
  • 12
  • 51
  • 55
  • Thanks. Is there any possibility you could adapt that to be used in TextWrangler or any other program using a powerful Find and Replace function? – Tomulent Jun 10 '14 at 20:10
0

If there is really nothing more to be taken care of, search for \n([a-z]) (with find's "Matching" both "Case sensitive" and "Grep" enabled) and replace with \1. (The searched for expression does not have a leading blank, whilst the replacement does actually have one.)

Abecee
  • 2,365
  • 2
  • 12
  • 20