I'd like to run 'search and replace' for the carriage return character.

On a text import, it's not unusual to have carriage returns instead of soft returns.

How do I run a search and replace for 'invisibles' How can I do that? Is there an escape sequence that will enable the CR as a search term?

A work around is to re-import to libreoffice and do it there, or Wordperfect, but that's only acceptable if the text is still unformatted. It's time I got to grips with a solution in pages, or AppleScript




MacBook Air 11″, macOS 10.15

Posted on May 23, 2022 1:04 PM

Reply
Question marked as Top-ranking reply

Posted on May 23, 2022 1:26 PM

You show invisibles via the View menu > Show Invisibles. This is a toggle so typing shift+cmd+i will do the same.


When you open a text document with CRLF line endings (Windows), Pages v11.1 (and v12 later versions of macOS) will automatically remove the CR and leave the LF as paragraph marks denoted by the ¶ character. Any soft returns in that document are also changed to newlines. There is no need to manually use Find/Replace to locate the Windows line-endings or soft returns as they are already replaced.

13 replies
Question marked as Top-ranking reply

May 23, 2022 1:26 PM in response to Old_Yorkshireman

You show invisibles via the View menu > Show Invisibles. This is a toggle so typing shift+cmd+i will do the same.


When you open a text document with CRLF line endings (Windows), Pages v11.1 (and v12 later versions of macOS) will automatically remove the CR and leave the LF as paragraph marks denoted by the ¶ character. Any soft returns in that document are also changed to newlines. There is no need to manually use Find/Replace to locate the Windows line-endings or soft returns as they are already replaced.

May 28, 2022 8:23 AM in response to Old_Yorkshireman

As I have stated, if you open a Windows text file with its inherent CRLF line-endings and user added soft-return characters in Pages v11.1 or even Pages v12, the application automatically converts those line-endings and soft-returns to just LF, or what you see via the show invisibles as paragraph (pilcrow ¶) marks.


If you enter soft returns in Pages with the previous document open, they will be shown by ⏎ with invisibles on. These can can searched for with Find: \i and either replaced with nothing, or with a newline \n, or any other character as needed.


Pages cannot export to .ODT — only as Word, RTF, or Text for reopening in LibreOffice Writer. Word v16.31 and later can open PDF documents exported by Pages and convert them to Word .docx documents. Pages does not re-add CRLF line endings on export to any document format.

May 31, 2022 8:05 AM in response to VikingOSX

Hello again


yes, Pages doesn't deal with .odt. I was actually thinking of ODF. Open Document Format, and when I go and look I find that ODT is the LibreOffice version. Maybe when it was Openoffice it was still ODF. Not that that matters.


So despite the long winded and unnecessary verbiage, what I take away as an answer to :

" run 'search and replace' for the carriage return character."


is, or would have been,


"Using the escape character of ' \' Pages 'Find and Replace' will look for line feeds defined as \i and LF/Carriage return as \n."



I'll see if I can find the documentation for other 'features'

Job done!

Thanks very much.

R





May 27, 2022 6:48 AM in response to VikingOSX

The discussion is splintering - lets bring this thread back together. It starts with a block of text as shown below, For sake of common definition, I refer to a new line as being the control shown as a down and left arrow when using 'show invisibles' in Pages.. A carriage return/new line, also known as a paragraph marker is the reversed P.

As part of a presentation standard, text is always without new lines keyed. text flow is handled by the application calculating presentation line length according to the paper and margins, with indent/outdent overrides(if any) and the font character widths. Sentence endings are denoted by a full stop and two spaces (two spaces being a convention, not a requirement.


Here's an example of pages in action.



Now, as per my first posting, we desire to remove the new line/carriage return characters from within the text. In this case, and frequently in imported text, we have to re-insert a space. to preserve a word separation. (dealing with any double spaces is another requirement which requires a search and replace for a space, outside the scope of this query)


So going back to the query, "Is it possible to use Pages find and replace to find new line/carriage return characters, which are normally 'invisible' and non-printing?"


The find box cannot be persuaded to search for controls - for example 'start underline' or 'font change' and all the rest. To do so would require a means of defining the targeted control, typically either by keying the control to the search box, or by using an escape character combination - specifying a new line as /n for example. You can see below that your suggestion of searching for \n (with or without quotes) does not find newline/carriage return, though it does find cr/lf (carriage return line feed) otherwise named Paragraph ends


This is not unexpected, as allowing access to these codes is a sure fire way of having casual users destroy documents, and blame Pages for their own ineptitude.


So the question seems to have been resolved by your posting showing direct file editing from outside Pages - an environment where you can address characters by their hex values.


Many thanks for the suggestion, but exporting from Pages to .odt or .txt and using the wysiwyg facility of Libreoffice or Wordperfect keeps the process at user level. macros are also available to deal with the preservation of paragraphs and sundry other items previously mentioned.

You seem to confirm my own research and trials that Pages cannot interrogate its own internal structure.


I really appreciate your time and suggestions though.


Many Thanks

R



May 23, 2022 1:53 PM in response to VikingOSX

And I might further add that looking for a specific newline (\n) to replace with a soft-return (\i) will require you to use the arrow keys on the find/replace panel to light-up the newline that you want to change to a soft return, and then choose Replace.


In this image, there were two newlines (paragraph marks). I replaced the second one with a soft return with its readily identifiable invisible character shown.


May 24, 2022 12:58 PM in response to Old_Yorkshireman

using pages 11.1 Find and replace does not find "/n" because it cannot search for controls. - or am I missing something here?


find '/n' finds that sequence of characters within the text.


The use of an escape character and specifier works elsewhere. I have to say that most Pages users will not require the facility, and don't understand what happens under the covers within a document. The overall simplicity and excellence of Pages for both text and layout outweighs this niche issues.

But - I'd still like to automate the job.



May 25, 2022 5:41 AM in response to Old_Yorkshireman

Starting with a text file that contains carriage returns (CR) and/or linefeed (LF) in line ending pairs, or separately, the following Terminal commands (your choice) will remove any occurrence of these characters and write the result to a new text file, before opening the result in Pages. You may need to deal with joined words where the removed character separated them.


cd ~/Desktop
tr -d '\12-\15' < crlf.txt > crlf_plain.txt
tr -d '\12-\15' < crlf.txt | open -f -a Pages



May 31, 2022 8:33 AM in response to Old_Yorkshireman

You are welcome.


What is undocumented for search and replace is that you can search for any character that you can find in the Emoji & Symbols (character) viewer (ctrl+cmd+spacebar). For instance, there is a particular emoji in a current Pages document, and if I place the cursor in the Find field and then press ctrl+cmd+spacebar to open the character viewer, I can then double-click the specific character (emoji in this case) to insert it into the Find field, and it locates the emoji in the document…


May 24, 2022 10:16 AM in response to VikingOSX

Thanks, I'm familiar with the inside of Word and various other WP systems.


The specific use case is that a chunk of text has 'arrived' with line feed (down left arrow) into Pages. To reflow this text requires that the hard line feed is removed, and may be replaced with a space.

This can be done manually using the keyboard, and looping a keyboard macro - say

'Align to left margin, backspace, insert space, cursor down'


To account for paragraph ends, this needs to be run manually.


If it were possible to search for the line feed, then the sequence becomes something like

first pass, identify real paragraph breaks. 'Search for a double line feed, and replace with a temporary paragraph marker character (A special character, say) '

second pass. remove unwanted line feed 'search for line feed, replace with space'

third pass. replace paragraphs ' search for the marker, replace with CR/LF (hard carriage return)



Other Wp systems have the ability to search for control characters embedded in the text. Such things as font changes, start bold, end bold, and so on. Word frequently doesn't understand the concept of a start and end control, preferring to start something and leave it trailing, or repeat definitions, but that's out of scope for this enquiry.


I'm asking whether anyone has been able to automate this process. If you cut and paste, say, a large block of text from gutenberg, it will paste into Pages with hard line feeds, as befits a fixed line length. My scanner also prefers to do this, for obvious reasons. I'd like to solve the problem within Pages.




May 24, 2022 10:22 AM in response to VikingOSX

Thanks for the example. The question is to remove the soft return, and/or the paragraph character so as to flow the entire text onto one line. My example shows Paragraphs being retained.

Incidentally, being able to search for spaces is also relevant. In the case of searching for 'stop, space' i.e. end of sentence, and replace with 'stop, space space' as a convention across large swathes of text.


Extending the example use cases - You are given 80,000 words of text and have to replace underlines with a font change to italic. ???



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

I'd like to run 'search and replace' for the carriage return character.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.