-
1. Re: HELP! GREP Line Return Removal
[Jongware] May 20, 2011 1:07 PM (in response to RichardM0701)You should have enabled Hidden Characters -- that would have made the picture a bit more easy to comprehend. For example, it's still possible your "line returns" are either Hard Returns or Soft Line Breaks. (I'll be assuming they are regular hard returns, 'cause that's what ignoramii authors usually use when submitting their files .)
There is no need to use GREP; what you want here is find [space] [hard return] [space] [space] [space] [space], and you can enter this in regular Find/Change like this:
^p
(you'll have to take my word for the correct number of spaces). It could be done the same with GREP, only you'd use \r instead of ^p (that's all in the documentation), or with less keystrokes to find those 4 spaces:
\r {4}
(.. Hey wait, that's also four keystrokes!)
-
2. Re: HELP! GREP Line Return Removal
[Jongware] May 20, 2011 1:10 PM (in response to [Jongware])Uh. What do you mean "the character is important"? Is that because your seemingly blank lines also contain four spaces? (Note what I said above about the Hidden Characters ...)
Oh okay, you need GREP. Try this:
\r {4}(?=\S)
The additional (?=\S) stuff checks if the four spaces are followed by a character of the set '\S', which is an abbreviation for "not-a-space". (In this sense, the hard return itself also ought to be a space, and so space-space-space-space-hard return oughtn't be matched. .. You might want to make sure of that, though.)
-
3. Re: HELP! GREP Line Return Removal
RichardM0701 May 20, 2011 1:38 PM (in response to [Jongware])Thank you for your time and response JongWare.
Your right, I spaced out on the hidden characters (get it? spaced out...)
Ok moving on, here is a screen capture with the characters showing:
Great suggestions! Unfortunately, ^p removes all my line returns which I’m not trying to do just yet, I just want to fix my paragraphs. In this case, I think the GREP would need to know there is a character after the 4 spaces (so it doesn’t go after all my line returns)? What do you think?
-
4. Re: HELP! GREP Line Return Removal
RichardM0701 May 20, 2011 1:41 PM (in response to [Jongware])Perfect!!! This was what I needed. Works like a charm!
Thanks!
-
5. Re: HELP! GREP Line Return Removal
RichardM0701 May 20, 2011 1:57 PM (in response to [Jongware])Oh okay, you need GREP. Try this:
\r {4}(?=\S)
The additional (?=\S) stuff checks if the four spaces are followed by a character of the set '\S', which is an abbreviation for "not-a-space". (In this sense, the hard return itself also ought to be a space, and so space-space-space-space-hard return oughtn't be matched. .. You might want to make sure of that, though.)
So if I want to make sure that the this only fixes my paragraphs and does not merge my headings (see screenshot), I could use something to check for like 15 or more characters before the code (sense headings are single words no more than 15 characters) like you have done on the back end of the code above?
(15=\S)\r{4}(?=\S)
-
6. Re: HELP! GREP Line Return Removal
P Spier May 20, 2011 2:07 PM (in response to RichardM0701)Looking at the new screen grab, it appears that there are 10 spaces at the beginning of the lines, but no spaces at all before the hard returns (not to mention the even larger strings of spaces at the start of the headings. Are you purposely leaving some spaces to provide the iindents? That's a bad way to work.Indents should all be set as part of the paragraph style.
I'd be inclined to to several steps here, starting with trying to isolate the paragraphs that are headings and apply a style. Based on the very small example, I think you could use a search for ^\s{10}\s+ (the ^ says the spaces are at the beginning of the paragraph and the rest says "more than ten" since there seems to be variability). In the change formatting assign a unique parargraph style.
Do the same thing, but this time search only for ^\s{10} and apply a different unique style.
Now you can fix the spaces and remove the returns. The first search will clear the spaces in front of the headings: Search for ^\s+ and set the find format to the heading style you assigned. Clear the change format, and leave the change to field blank. This will emove all the leading spaces from the heading paragraphs. It's important to do this before the next step.
Now search for \r\s+ and set the find format to the second style you assigned above for paragraphs starting with 10 spaces. Put the cursor in the change to field and press spacebar once to add a space. This will replace all the mid-paragraph returns and extra spaces with a single space, but the first line will still have leading spaces. Search again for ^\s+ with the find format still set to the same style and clear the change to field to remove the last leading spaces for the paragraphs.
Jongware, did I get that right?
-
7. Re: HELP! GREP Line Return Removal
[Jongware] May 20, 2011 2:21 PM (in response to P Spier)P Spier wrote:
Jongware, did I get that right?
Indeed I think you do. Taking small steps is of key importance here.
I think the OP misunderstood my "^p plus imaginary spaces" jib -- I typed a single space before the ^p and four after, but of course they weren't visible in my post ... But specifying the exact number in GREP ought to be the safest way anyway, and when combining it with a lookahead for not-a-space, I think it's possible to filter out the 'plain' paragraph text and clean up just that.
-
8. Re: HELP! GREP Line Return Removal
RichardM0701 May 20, 2011 2:29 PM (in response to P Spier)Thank you Peter for the detailed response. Let me try out what you have posted. As you can see, I'm dealing with trying to take a non-tab delimitated .txt file from a software program and prepare it for a help file. You mentioned to apply a paragraph style in your comments. I have been trying all day to figure out how to apply a paragraph style from the find and replace. Do you have any useful articles that you know of? I could not find anything on a Google search nor Lynda.com.
-
9. Re: HELP! GREP Line Return Removal
RichardM0701 May 20, 2011 2:33 PM (in response to RichardM0701)Nevermind, it just bit me in the face, Change format! Thank you!
-
10. Re: HELP! GREP Line Return Removal
P Spier May 20, 2011 2:39 PM (in response to RichardM0701)If you haven't already, I suggest you read the help files about GREP, too. It's EXTREMELY powerful, but because of the power you need to be pretty careful about what you do to avoid a disaster. You might want to make a backup copy of the file for safety.
Peter Kahrel also has published a terrific PDF/eBook about GREP in ID at O'Reilly for about $10 that I find indispensible.






