* replace a textblock in multiple files
@ 2006-09-25 16:55 C.Strobl
0 siblings, 0 replies; 9+ messages in thread
From: C.Strobl @ 2006-09-25 16:55 UTC (permalink / raw)
hello all,
only a short and simple question: whats the best way to replace a
textblock in multiple files.
thanks and i hope the question is not to easy
christian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: replace a textblock in multiple files
[not found] <mailman.7384.1159203371.9609.help-gnu-emacs@gnu.org>
@ 2006-09-26 0:52 ` Benjamin Rutt
2006-09-26 11:18 ` AW: " C.Strobl
0 siblings, 1 reply; 9+ messages in thread
From: Benjamin Rutt @ 2006-09-26 0:52 UTC (permalink / raw)
<C.Strobl@dlr.de> writes:
> hello all,
> only a short and simple question: whats the best way to replace a
> textblock in multiple files.
> thanks and i hope the question is not to easy
> christian
M-x dired
mark desired files with 'm'
Q
--
Benjamin Rutt
^ permalink raw reply [flat|nested] 9+ messages in thread
* AW: replace a textblock in multiple files
2006-09-26 0:52 ` replace a textblock in multiple files Benjamin Rutt
@ 2006-09-26 11:18 ` C.Strobl
2006-09-26 12:09 ` regexp question C.Strobl
[not found] ` <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 9+ messages in thread
From: C.Strobl @ 2006-09-26 11:18 UTC (permalink / raw)
thanks, but maybe my question was too short.
1) i want to work on several subdirectories, not only in one directory
2) i want to replace blocks consisting of more than one line.
is that possible at all
tanks again
christian
p.s. i know it's always possible with programming elisp. but i want to know if it's possible with simple emacs commands?
> -----Ursprüngliche Nachricht-----
> Von: help-gnu-emacs-bounces+c.strobl=dlr.de@gnu.org
> [mailto:help-gnu-emacs-bounces+c.strobl=dlr.de@gnu.org] Im
> Auftrag von Benjamin Rutt
> Gesendet: Dienstag, 26. September 2006 02:52
> An: help-gnu-emacs@gnu.org
> Betreff: Re: replace a textblock in multiple files
>
> <C.Strobl@dlr.de> writes:
>
> > hello all,
> > only a short and simple question: whats the best way to replace a
> > textblock in multiple files.
> > thanks and i hope the question is not to easy christian
>
> M-x dired
>
> mark desired files with 'm'
>
> Q
> --
> Benjamin Rutt
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* regexp question
2006-09-26 11:18 ` AW: " C.Strobl
@ 2006-09-26 12:09 ` C.Strobl
2006-09-26 17:16 ` Peter Dyballa
[not found] ` <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 9+ messages in thread
From: C.Strobl @ 2006-09-26 12:09 UTC (permalink / raw)
hello all,
i want to replace a block beginning with <column_right> and ending with
</column_right>, with a variable number of lines between with another
text block. is that possible with regular expressions and if yes, how?
i don't know how to find an optional number of complete lines.
how can i find this text block with a regular expression?
<column_right>
<!-- background attribute options: black, white, grey,
blue, red, green, orange -->
<feature_block background="orange">
<feature_text></feature_text>
<feature_image
height="1">spacer_grey.gif</feature_image>
<feature_text></feature_text>
<feature_image
type="intern">projects/gitews/logo_175.gif</feature_image>
<feature_text></feature_text>
<feature_image
height="1">spacer_grey.gif</feature_image>
<feature_text></feature_text>
<feature_text>Work Package 4100</feature_text>
<feature_text>provided by XYZ</feature_text>
<feature_text></feature_text>
<feature_image
height="5">spacer_grey.gif</feature_image>
<feature_text></feature_text>
<feature_header>Contact:</feature_header>
<feature_text></feature_text>
<feature_text></feature_text>
</feature_block>
</column_right>
christian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: regexp question
2006-09-26 12:09 ` regexp question C.Strobl
@ 2006-09-26 17:16 ` Peter Dyballa
2006-09-29 22:03 ` Dieter Wilhelm
0 siblings, 1 reply; 9+ messages in thread
From: Peter Dyballa @ 2006-09-26 17:16 UTC (permalink / raw)
Cc: help-gnu-emacs, rutt.4
Am 26.09.2006 um 14:09 schrieb <C.Strobl@dlr.de>:
> how can i find this text block with a regular expression?
<column_right>[-_ !",./0-9:<=>A-Za-z
]*</column_right>
- has to come first, _ is just close, then come SPACE and TAB, ...,
and finally a newline, C-q C-j.
To determine the characters in the region do this shell-command-on-
region:
sed -e 's/\(.\)/\1·/g' | tr '·' '\012' | sort -u
--
Greetings
Pete
"I wouldn't recommend sex, drugs or insanity for everyone, but
they've always worked for me."
-- Hunter S. Thompson
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: replace a textblock in multiple files
@ 2006-09-26 19:45 Jay Bingham
0 siblings, 0 replies; 9+ messages in thread
From: Jay Bingham @ 2006-09-26 19:45 UTC (permalink / raw)
On Tuesday, September 26, 2006 6:18 AM Christian wrote:
> 1) i want to work on several subdirectories, not only in one
> directory
> 2) i want to replace blocks consisting of more
> than one line.
> is that possible at all
> p.s. i know it's always possible with programming elisp. but
> i want to know if it's possible with simple emacs commands
Yes, it can be done. You did not say which version of Emacs you are
running, that might make a difference. That said here is how I would
do it if I were running version 21.3.
Load the ibuffer.el package, load the dired-x.el package.
The ibuffer.el package is available from:
www.shootybangbang.com/software/ibuffer.el
The dired-x.el package is a part of Emacs but must be explicitly
loaded/enabled in your .emacs.
Once you have these to packages active you can use the % g dired
command to locate the files that contain block of text you want to
replace. Then you can use the C-u F dired command to load the files.
Once the files are loaded invoke ibuffer and use the / c command to
limit the view to files containing the block of text. Then use the t
command to mark all the files. Finally use the U command to replace
the block of text defined by a regular expression with the new text.
There may be other ways to do this, but this is the easiest way that
I know of using simple emacs commands.
Good Luck,
__
J_)
C_)ingham
_____________________________________________________________________
PrivatePhone - FREE telephone number & voicemail.
A number so private, you can make it public.
http://www.privatephone.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: regexp question
[not found] ` <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>
@ 2006-09-27 7:58 ` Florian Kaufmann
0 siblings, 0 replies; 9+ messages in thread
From: Florian Kaufmann @ 2006-09-27 7:58 UTC (permalink / raw)
> i want to replace a block beginning with <column_right> and ending with
> </column_right>, with a variable number of lines between with another
> text block. ext block with a regular expression?
I would use:
<column_right>\(.\|^J\)*?</column_right>
Where the ^J results from pressing C-q C-j.
The details: Since the dot . does much any character but the newline, I
use the construct \(.\|^J\) which now matches really any character. *?
is the lazy version of the greedy *. Meaning that as few as possible
are selected. This prevents from selecting too much. Only * instead of
*? would much both of the following lines instead of only one.
<column_right>line1</column_right>
<column_right>line2</column_right>
However, my regex fails to match nested tags. In the following example
<column_right><column_right></column_right></column_right>
the match is
<column_right><column_right></column_right>
which is not what you want. I don't know how to make a regular
expression which would also support this case. I'm sure you would find
the answer in the book "Mastering regular expressions"
Flo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: regexp question
2006-09-26 17:16 ` Peter Dyballa
@ 2006-09-29 22:03 ` Dieter Wilhelm
2006-09-30 8:53 ` Peter Dyballa
0 siblings, 1 reply; 9+ messages in thread
From: Dieter Wilhelm @ 2006-09-29 22:03 UTC (permalink / raw)
Cc: C.Strobl, help-gnu-emacs, rutt.4
Peter Dyballa <Peter_Dyballa@Web.DE> writes:
> Am 26.09.2006 um 14:09 schrieb <C.Strobl@dlr.de>:
>
>> how can i find this text block with a regular expression?
>
> <column_right>[-_ !",./0-9:<=>A-Za-z
> ]*</column_right>
>
> - has to come first, _ is just close, then come SPACE and TAB, ...,
> and finally a newline, C-q C-j.
>
> To determine the characters in the region do this shell-command-on-
> region:
>
> sed -e 's/\(.\)/\1·/g' | tr '·' '\012' | sort -u
^
I assume above construct is necessary for (older) UNIX systems? I
tried:
sed -e 's/\(.\)/\1\n/g | sort -u
which is working on my Gnu/Linux system.
--
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: regexp question
2006-09-29 22:03 ` Dieter Wilhelm
@ 2006-09-30 8:53 ` Peter Dyballa
0 siblings, 0 replies; 9+ messages in thread
From: Peter Dyballa @ 2006-09-30 8:53 UTC (permalink / raw)
Cc: C.Strobl, help-gnu-emacs, rutt.4
Am 30.09.2006 um 00:03 schrieb Dieter Wilhelm:
> sed -e 's/\(.\)/\1\n/g | sort -u
>
> which is working on my Gnu/Linux system.
Your shell is faulty. A quoted sequence has to start and to end.
\n does not seem to work for me ...
Anyway, Florian Kaufmann's \(.\|^J\)*? is the optimal expression: it
does not need a contents analysis.
--
Mit friedvollen Grüßen
Pete (:
_ / __ - -
_/ \__/_/ - -
(´`) (´`) - -
`´ `´
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2006-09-30 8:53 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.7384.1159203371.9609.help-gnu-emacs@gnu.org>
2006-09-26 0:52 ` replace a textblock in multiple files Benjamin Rutt
2006-09-26 11:18 ` AW: " C.Strobl
2006-09-26 12:09 ` regexp question C.Strobl
2006-09-26 17:16 ` Peter Dyballa
2006-09-29 22:03 ` Dieter Wilhelm
2006-09-30 8:53 ` Peter Dyballa
[not found] ` <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>
2006-09-27 7:58 ` Florian Kaufmann
2006-09-26 19:45 replace a textblock in multiple files Jay Bingham
-- strict thread matches above, loose matches on Subject: below --
2006-09-25 16:55 C.Strobl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).