LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-26-2009, 07:11 AM   #1
linuxqueric
Member
 
Registered: Apr 2007
Posts: 41

Rep: Reputation: 15
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.

What am I missing?
 
Old 10-26-2009, 09:17 AM   #2
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
You're missing .

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.
 
Old 10-26-2009, 09:41 AM   #3
linuxqueric
Member
 
Registered: Apr 2007
Posts: 41

Original Poster
Rep: Reputation: 15
Great. That worked. Thanks!
 
Old 10-26-2009, 10:41 AM   #4
linuxqueric
Member
 
Registered: Apr 2007
Posts: 41

Original Poster
Rep: Reputation: 15
Next problem. The regexpr .*~ succeeds in getting rid of the file~, but leaves an empty paragraph:

file1

file2

Following the openoffice.org wiki (http://wiki.services.openoffice.org/...ns_in_Writer):
Quote:
^$ 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:].
 
Old 10-26-2009, 03:15 PM   #5
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
Maybe

^[:space:]*$

would match?
 
Old 03-03-2013, 07:00 PM   #6
JHPArizona
LQ Newbie
 
Registered: Jun 2007
Location: Northern Arizona
Distribution: Redhat / Knoppix / Ubuntu / MacOSX
Posts: 8

Rep: Reputation: 0
Remove blank lines

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.

Thanks, Jim
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Regular Expression in VIM search and replace vijay_babu1981 Linux - Newbie 8 10-22-2009 07:49 AM
search & replace raj_sony2001 Linux - General 4 10-05-2006 02:05 PM
Best search & replace program geokker Linux - Software 3 09-28-2005 03:41 PM
Kate - Regular Expression Replace and Other Features? apachedude Linux - Software 0 01-04-2005 01:49 PM
regular expression search/replace question (HELP!!! :) amytys Programming 5 09-06-2004 02:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration