Regular Expression Search & Replace in Writer or gedit
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Regular Expression Search & Replace in Writer or gedit
I've got a list of files that I've copied from my terminal and pasted into gedit and into OO.o writer. Since the files are all created by gedit, in each case there is both
file
and
file~.
I want to get rid of all the 'file~' lines. I thought I could do search and replace using *~, but this doesn't work.
With regexp * means that previous character can repeat, it's not a wildcard. Therefore you need .*, in which . is the wildcard and * means it can repeat.
^$ will match an empty paragraph, which can be replaced by say nothing, in order to remove the empty paragraph.
gives me "Search string not found."
A bit of experimentation indicates that there are hidden spaces before each new paragraph mark--I can arrow through the spaces, but they do not show with View Nonprinting Characters, the way spaces I enter do. But if I manually remove the spaces, then ^$ works to remove the empty paragraph.
Now my problem is to figure out how to replace all those spaces. Just putting a blank space into the "Find" box doesn't do it, not does using [:space:].
Yes, I know this is a very old thread but... it helped me research the solution I needed but did not have the exact solution so..... in the event that someone else searches and needs the same solution, I am adding to this thread.
As the title says, I needed to remove a large number of blank lines. I most likely got into this need because I did a search and replace, but ... probably not correctly, and removed the text I wanted removed but left a blank line for each replace. Whew!, now that the preamble is out of the way....
To remove blank lines, you can try searching for \n OR \CR OR \CRLF or any of the other programming methods of creating a new line, depending on the source of the text and replacing with nothing. e.g. search for \n and replace with nothing. You might want to test a few lines before doing a Replace All to prevent getting one line of run-on text.
If you are unsure of what format the blank line takes, you can highlight the entire blank line (shift+ (down arrow)) and click the replace button or select replace from the search menu. To extend the easy use of Replace, you can highlight what you want to replace in the document, then select Replace eliminating the need to type in the 'Search for' box.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.