Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CrockAlley

macrumors newbie
Original poster
Apr 16, 2011
13
0
I have a lot of old documents that have unnecessary line breaks. I want to find/replace in TextEdit. It's easy enough to do, but it's a tedious process to do over and over.

Example:
Code:
I have a lot of really
old text files that have
line breaks like this
to keep the text at a
certain width. 

But when I'm trying to
use Speak Screen, the
line breaks mess up
the speech.

In TextEdit, I copy and paste two hard returns in the FIND field, and replace that with some garbage text (let's say "garbagetext"). Replace all. Then I find all single hard returns and replace with a space. Then I find garbagetext and replace with two hard returns. (The garbagetext stuff is to preserve the paragraph breaks.)

Is that something that I could automate? I have never used Shortcuts and taking a quick look at tutorials, it looks like a bunch of learning that I'd need to do, which I'm happy to do, but I'd like to know that it's something that can be done before I dig in too deeply.

Thanks for any help!
 
Typically I do this stuff in BBEdit, open all the documents at once, open the multi-file find, set the Find: to
Code:
([^\n])\R(?=[^\n])
and the replace to
Code:
\1
(do note there is a space at the end which MR is stripping)
Make sure "Grep" is checked, and then check "Open Editing Windows".

Or if you're comfortable with the command line, awk or sed might work.
Is that something that I could automate? I have never used Shortcuts and taking a quick look at tutorials, it looks like a bunch of learning that I'd need to do, which I'm happy to do, but I'd like to know that it's something that can be done before I dig in too deeply.
You probably could figure it out but I played around with it for a few minutes, it doesn't like regex capture groups and using the split text/replace text/combine text actions I wasn't easily able to get it to work. It won't let me split by double newlines, it won't replace single newlines with double newlines, and it won't put double newlines back (that's what i tried to do anyways). Honestly it's an awful tool for any real kind of manipulative programming like this, it can only do basic automation.
 
  • Like
Reactions: CrockAlley
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.