March 5 2008 • 3:17 AM

Merging Paragraphs with Find/Change

Ginny wrote:

I’ve imported 40 pages of directory listings each with a hard return at the end of a line. Is there a way to globally change the hard returns to soft returns, or forced line breaks, once the text is imported from a word doc into InDesign?

The goal is to separate each member’s info with a space after attribute using the hard return, with the rest of each members info spaced with leading only.

This requires a tried-and-true technique: A triple Find/Change.

Lets take some sample text, as you described:

fc-textstart.gif

It’s easy to replace a return with a soft return in Find/Change, (Find: ^p, Change: ^n) but that’s usually going overboard. You end up with one monstrously long paragraph with no easy way to break them up into smaller ones.

So you start out by figuring out what unique thing — a text string, a character style, a certain number of returns — only appears immediately before or at the beginning of your “real” paragraphs and on no others. Then you use Find/Change to temporarily replace that unique identifier with something that doesn’t contain any return characters. I often use %%%.

For the sample above, the “real” paragraphs are identified by two returns in a row (pretty common). So we replace that identifier with a unique string.

fc-1.gif

fc-1text.gif

Now that the only returns in the text are ones that shouldn’t be there, you can safely replace them with what you want — in your case, a soft return (forced line break), but often people need to replace end-of-line returns with a space or a tab.

fc-2.gif

fc-2text.gif

The third and final Find/Change replaces the unique paragraph separator we added with an actual return character.

fc-3.gif

fc-3text.gif

So now you can easily select all the text and apply paragraph formatting, such as Space Before, that does what you want it to.

fc-textfinal.gif

19 Responses discussing this post. Add yours below.

  1. Christa
    March 5th, 2008 • 8:57 amLink

    See, easy solutions like this is why I love this blog! Thanks :)

  2. Martin Braun
    March 5th, 2008 • 9:10 amLink

    Hi Anne-Marie,

    why not doing this in two steps?

    1. Replace ^p with ^n
    2. Replace ^n^n with ^p

    Martin

  3. Martin Braun
    March 5th, 2008 • 9:18 amLink

    Hi Martin

    why not doing this in one step?

    1. Grep-Replace \r(\r*) with \n$1

    Martin

    (Sorry, I’m a little bit schizoid this morning…)

  4. March 5th, 2008 • 10:57 amLink

    This is great!
    I did it the long way some days ago!
    Thanks for sharing this!
    Best regards from Austria
    Martin

  5. March 5th, 2008 • 11:01 amLink

    …by the way, are there some free ebooks and/or other resources out there to really lern GREP?
    Martin

  6. Alex Lemos
    March 5th, 2008 • 11:30 amLink

    I always do it the way Martin Braun suggested (the first one :P) and it works great.

  7. Martin Braun
    March 5th, 2008 • 12:09 pmLink

    Hi Martin (the “not me” one),

    I learned Grep with the Documentation that ships with BBEdit (a Mac-only-application). You can download a demo at http://www.barebones.com.

    Meanwhile I improved the search-pattern:

    grep-replace \r(\r?)\r* with \n$1

    This will strip out unnecessary paragraphs.

  8. Wa Veghel
    March 5th, 2008 • 12:57 pmLink

    Yes, GREP is by far the fastest way here

  9. Wa veghel
    March 5th, 2008 • 1:05 pmLink

    >…by the way, are there some free ebooks and/or other resources out there to really lern GREP?
    Martin

    Yes, take a look at O’reilly, They have a great PDF on GREP in InDesign (not free however)

  10. Steve Werner
    March 5th, 2008 • 1:14 pmLink

    If you have lots of time and no money, Google “GREP.” There are lots of resources, though not oriented to InDesign.

    If your time is worth money, it’s worth paying for something well-written.

  11. March 5th, 2008 • 1:25 pmLink

    Well I wondered how long someone would put up a GREP solution that’s faster. ;-)

    Still, not everyone has CS3 or is in a position to export text to a GREP-ready text processor for this; so the plain old F/C works just as well.

    For a great GREP resource, don’t forget Peter Kahrel’s wonderful PDF e-book, GREP in InDesign CS3. Well worth the $9.99! I wrote about it in a blog post a couple months ago.

  12. Wa Veghel
    March 5th, 2008 • 1:56 pmLink

    >or a great GREP resource, don’t forget Peter Kahrel’s wonderful PDF e-book, GREP in InDesign CS3. Well worth the $9.99!

    That is the one I meant, see O’reillys

  13. Andrew Herzog
    March 5th, 2008 • 5:29 pmLink

    3 step find and change — good
    2 step find and change –better
    1 step grep –best
    1 step grep that fixes my lunch –amazing

    I wonder, has anyone written a book that explains problem solving techniques? How to THINK through problems, APPLY what they know, and USE available resources to come up with the most amazing solution?

    Not that the book has to be geared toward any particular application or platform, just something that can help people learn to be problem solvers and make the most use of what they have.

    I have seen people who can’t even attempt anything similar to this. (They can’t think outside the box.)

    And some who spend their time outside the box when what they need is to realize the box has everything they need.

  14. March 5th, 2008 • 6:20 pmLink

    I second Peter Kahrel’s e-book. Well worth the $9.99 and then some.

  15. PaulK
    March 5th, 2008 • 6:44 pmLink

    I didn’t notice that the OP specified that each entry set was separated by a double hard return after the Interest: line. Too me the problem’s a bit of a no brainer given the double hard return. What if you only had the word Interest: to key on? Or maybe I’m misreading something here.

  16. March 5th, 2008 • 9:48 pmLink

    The thing about “no-brainers” is that they’re only no-brainers to people who forgot they too, at one point, needed to figure it out. Note the category for the post: Beginner’s Corner.

    If you only had the word “Interest” to key on, then instead of replacing two returns in a row with the %%%, you’d replace one return followed by the word “Interest” with “%%%Interest”.

  17. Lazza
    March 5th, 2008 • 10:46 pmLink

    To Andrew Herzog

    How to think!

    Edward De Bono has written numerous books on how to think.

    check it out!

  18. Peter Spier
    March 5th, 2008 • 10:48 pmLink

    Seems to me that using %%%Interest you are going to end up splitting off the interest and adding it to the following name. Perhaps it would be better to find all instances of Interest and apply a new paragraph style name to that paragraph, then find any other style and change the paragraph return to a line break (bear in mind I haven’t tested this).

    Peter

  19. Martin Braun
    March 7th, 2008 • 5:43 pmLink

    Hi Peter,

    your solution with paragraph styles ist great and works in CS3 and older Versions. A geeky grep way in this case is the “negative lookahead”. Try this (and be amazed):

    Search: ^((?!Interest:).*)\r
    Replace: $1\n

    Greetings from Germany
    Martin

Subscribe to the Discussion

Get the ongoing discussion surrounding "Merging Paragraphs with Find/Change" delivered to you. Click here to subscribe via RSS.

Leave a Reply

You can use limited HTML tags, such as <em></em> for emphasis/italics and <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

InDesignSecrets reserves the right to edit and/or remove posts and comments.