| User: editor -- 2008-05-29 << 162 164 >> |
| Hits: 769 |
| Type: Advanced search and replace |
| Search all Advanced search and replace examples |
| Description: |
| How to remove unnecessary line breaks in a text file? I have some text which containing many hard returns, I need to remove them but need to keep the proper line breaks. |
| Input Sample: |
| The hard-hitting adverts - which were designed by teenagers - aim to show the true consequences of carrying a knife. One shows a man with a knife and a screwdriver in his chest, while others are of deep, gaping wounds to the body. |
| Output Sample: |
| The hard-hitting adverts - which were designed by teenagers - aim to show the true consequences of carrying a knife. One shows a man with a knife and a screwdriver in his chest, while others are of deep, gaping wounds to the body. |
| Answer: |
| Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps. |
| Some of your line breaks need to remove, but others should not remove such as paragraph end. Let's make a simple rule, do not remove line break in following cases: 1. If the line is shorter than 30(or other proper value), it might be paragraph end 2. If the line is ending by '.', '!' or '?', it might be paragraph end How to work with above rules using 'Replace Pioneer'? Procedures: 1. ctrl-o open the source text file 2. ctrl-h open 'Replace' dialog * set 'Replace Unit' to 'Line' * fill in the window under 'Search for pattern' to (note: '.*' means every line) * fill in the window under 'Replace with pattern': (note: $match means the line without <Return>, $match\n means line with <Return>) * fill in the window under 'If' to: 3. click 'Replace', done! Note: above operation means if the line is shorter than 70 and not ended by .!?, remove the line break. |
| Download Script: scripts/163.rst.zip |
Screenshot 1: Replace_Window |
Similar Examples: |
| How to remove/delete all blank lines in a text file? (75%) How to remove/delete consecutive duplicate lines in a text file? (74%) How to remove/delete all symbols in a text file? (72%) How to remove/delete all lines ending by a comma(,) in a text file? (70%) How to remove/delete all multi-byte characters in a text file? (70%) How to remove/delete all single-byte characters in a text file (68%) How to batch remove/delete first and last line of many text files? (67%) How to delete duplicate lines of a text file? (67%) |
Check Demo of Advanced search and replace |
| Keywords: |
| unnecessary line breaks remove unnecessary line break remove unnecessary line breaks hard return hard sar short line break break length remove returns using replace text containing remove line breaks using search and replace remove hard break remove hard line breaks remove every other line break remove paragraph without break |