2

I have some text like:

from her patient
scrutiny
and judicious criticism.

J.K.

WASHINGTON, D.C.

April, 1919.

And want to leave it like:

from her patient scrutiny and judicious criticism.

J.K.

WASHINGTON, D.C.

April, 1919.

How can I do it? I know you can replace newlines easily using the find & replace tool with /r/n but I don't know how to do this.

Some extra step: I also want to delete one newline if the previous line was empty and just had a newline character. Is that possible?

I don't know much about programming but I'm okay if I need to use bash or any Terminal tool to do this. However I hope I can use 4 cpu cores because the text file is really long.

2
  • One file or multiple? If it is one file, you cannot really parallel-process this. Please show what line ending characters your file uses. Is it \r\n\r\n for the double whitespace? Can the file be converted to Unix line endings?
    – slhck
    Apr 29 '19 at 16:09
  • It's one file sadly. But it's alright, I'll just leave it running then. The ending characters are always \r\n and also for the double whitespace (\r\n\r\n). I would prefer to have Windows line endings but it's alright anyway, I think it's going to be easy to change \r to \r\n.
    – Maccer
    Apr 29 '19 at 17:31
2
  • Ctrl+H
  • Find what: (?<=\S)\R(?=\S)
  • Replace with: # a space
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

(?<=\S)     # positive lookbehind, make sure we have a NON space character before
\R          # any kind of line break
(?=\S)      # positive lookahead, make sure we have a NON space character after

Result for given example:

from her patient scrutiny and judicious criticism.

J.K.

WASHINGTON, D.C.

April, 1919.

Screen capture:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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