Search a text and delete the line containing it

  • Follow


Hello

I'm completely new to emacs, and I've tried googling to get the answer 
to this, but I got nothing.

I want to delete lines from a rtf file. All these lines are based on the 
same pattern :

\li0\fi0 \par \b1 TEXT\b0 \par \par

I tried serching regexp \li0\fi0 \par \b1 .\b0 \par \par, but it didn't 
work.
Is that to do with the \ ?

I would be so glad if someone could help me with this.
Thanks

Ced
0
Reply Cedric 5/2/2005 4:36:47 AM

Cedric Delalande <laurycedNOSPAM@yahooPAS2SPAM.fr> writes:

> Hello
>
> I'm completely new to emacs, and I've tried googling to get the answer
> to this, but I got nothing.
>
> I want to delete lines from a rtf file. All these lines are based on
> the same pattern :
>
> \li0\fi0 \par \b1 TEXT\b0 \par \par
>
> I tried serching regexp \li0\fi0 \par \b1 .\b0 \par \par, but it
> didn't work.
> Is that to do with the \ ?
>
> I would be so glad if someone could help me with this.

Hi Ced, try out
M-x re-builder
for building complex regular expressions.

Be aware that where for interactive use \\ matches a literal
\, while the corresponding string regexp is "\\\\".

C-M-% (query-replace-regexp)
will allow you to do what you want.

The literal . is matched by \., or "\\.".

Best regards,

Adrian

> Thanks
>
> Ced

-- 
Adrian Aichner
 mailto:adrian@xemacs.org
 http://www.xemacs.org/
0
Reply Adrian 5/2/2005 6:57:23 AM


Adrian Aichner a �crit :
> Cedric Delalande <laurycedNOSPAM@yahooPAS2SPAM.fr> writes:

>>I want to delete lines from a rtf file. All these lines are based on
>>the same pattern :
>>
>>\li0\fi0 \par \b1 TEXT\b0 \par \par

> Hi Ced, try out
> M-x re-builder
> for building complex regular expressions.
> 
> Be aware that where for interactive use \\ matches a literal
> \, while the corresponding string regexp is "\\\\".
> 
> C-M-% (query-replace-regexp)
> will allow you to do what you want.
> 
> The literal . is matched by \., or "\\.".
> 

Does it mean it shoul look like

\\li0\\fi0 \\par \\b1 .\\b0 \\par \\par

???

Ced
0
Reply Cedric 5/2/2005 10:13:42 AM

Cedric Delalande <laurycedNOSPAM@yahooPAS2SPAM.fr> writes:

> Hello
>
> I'm completely new to emacs, and I've tried googling to get the answer
> to this, but I got nothing.
>
> I want to delete lines from a rtf file. All these lines are based on
> the same pattern :
>
> \li0\fi0 \par \b1 TEXT\b0 \par \par

Hi again, here is a practical approach:

While at the beginning of following line:
\li0\fi0 \par \b1 TEXT\b0 \par \par
press
C-M-s (isearch-forward-regexp)
C-y (yank)
C-s (isearch-forward-exit-minibuffer)

Now access the regexp so created with
C-M-s (isearch-forward-regexp)
M-p (isearch-ring-retreat-edit)
and edit it at will.

E.g. change TEXT to \(.+\) to search for any non-whitespace sequence
of one or more characters.

Copy this regexp and reuse it as the first argument in
C-M-% (query-replace-regexp)

If you use \1 as the second argument, you will replace
\li0\fi0 \par \b1 TEXT\b0 \par \par
with TEXT, where TEXT is non-whitespace sequence of one or more
characters.

Hope this helps,

Adrian

>
> I tried serching regexp \li0\fi0 \par \b1 .\b0 \par \par, but it
> didn't work.
> Is that to do with the \ ?
>
> I would be so glad if someone could help me with this.
> Thanks
>
> Ced

-- 
Adrian Aichner
 mailto:adrian@xemacs.org
 http://www.xemacs.org/
0
Reply Adrian 5/2/2005 6:31:04 PM

Thank you for your help.

Now I'd like to erase every blank line in a text file.
I tried with $, with ^, with \n, \r but it didn't work !

I've got this :

Hello

Line 1
Line 2

Line 3

Line 4

and I want :

Hello
Line 1
Line 2
Line 3
Line 4

Can someone give me a tip how to do this.

Ced

Cedric Delalande a �crit :
> Hello
> 
> I'm completely new to emacs, and I've tried googling to get the answer 
> to this, but I got nothing.
> 
> I want to delete lines from a rtf file. All these lines are based on the 
> same pattern :
> 
> \li0\fi0 \par \b1 TEXT\b0 \par \par
> 
> I tried serching regexp \li0\fi0 \par \b1 .\b0 \par \par, but it didn't 
> work.
> Is that to do with the \ ?
> 
> I would be so glad if someone could help me with this.
> Thanks
> 
> Ced
0
Reply Cedric 5/3/2005 3:01:21 PM

> Now I'd like to erase every blank line in a text file.
> I tried with $, with ^, with \n, \r but it didn't work !
>
> I've got this :
>
> Hello
>
> Line 1
> Line 2
>
> Line 3
>
> Line 4
>
> and I want :
>
> Hello
> Line 1
> Line 2
> Line 3
> Line 4
>
> Can someone give me a tip how to do this.
>

If the blank lines are actually empty then this should do it.
M-x flush-lines <RET> ^$ <RET>

If there might be spaces or tabs on the line
then this should match even if whitespace exists.

M-x flush-lines <RET> ^\s-*$ <RET>

0
Reply rgb 5/3/2005 4:38:54 PM

5 Replies
403 Views

(page loaded in 0.002 seconds)

Similiar Articles:













7/23/2012 9:39:27 PM


Reply: