unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ messages in thread

* Re: AW: replace a textblock in multiple files
       [not found] <mailman.7420.1159269539.9609.help-gnu-emacs@gnu.org>
@ 2006-09-26 15:44 ` Mathias Dahl
  2006-09-29  0:51   ` B. T. Raven
  2006-09-27  3:36 ` Benjamin Rutt
  1 sibling, 1 reply; 10+ messages in thread
From: Mathias Dahl @ 2006-09-26 15:44 UTC (permalink / raw)


<C.Strobl@dlr.de> writes:

> 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.

In dired, navigate one folder "higher" than where you want to start
your replacement. Then insert the directory you want to work with
using C-u i and add an R to the arguments at the prompt. This will add
all files recursively into the dired buffer and you can work with the
files from there.

The Q command should accept multi line blocks as long as you can find
a regexp to do it. If not, maybe you want to write a small helper
elisp function.

^ permalink raw reply	[flat|nested] 10+ 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; 10+ 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] 10+ messages in thread

* Re: AW: replace a textblock in multiple files
       [not found] <mailman.7420.1159269539.9609.help-gnu-emacs@gnu.org>
  2006-09-26 15:44 ` AW: replace a textblock in multiple files Mathias Dahl
@ 2006-09-27  3:36 ` Benjamin Rutt
  1 sibling, 0 replies; 10+ messages in thread
From: Benjamin Rutt @ 2006-09-27  3:36 UTC (permalink / raw)


<C.Strobl@dlr.de> writes:

> thanks, but maybe my question was too short. 
>
> 1) i want to work on several subdirectories, not only in one directory

M-x find-dired RET

then apply my rule as is.

> 2) i want to replace blocks consisting of more than one line.

yes just do a C-q C-j when you want to enter a newline.


-- 
Benjamin Rutt

^ permalink raw reply	[flat|nested] 10+ 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; 10+ 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] 10+ messages in thread

* Re: AW: replace a textblock in multiple files
  2006-09-26 15:44 ` AW: replace a textblock in multiple files Mathias Dahl
@ 2006-09-29  0:51   ` B. T. Raven
  0 siblings, 0 replies; 10+ messages in thread
From: B. T. Raven @ 2006-09-29  0:51 UTC (permalink / raw)



"Mathias Dahl" <brakjoller@gmail.com> wrote in message
news:u8xk6iqel.fsf@gmail.com...
> <C.Strobl@dlr.de> writes:
>
> > 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.
>
> In dired, navigate one folder "higher" than where you want to start
> your replacement. Then insert the directory you want to work with
> using C-u i and add an R to the arguments at the prompt. This will add
> all files recursively into the dired buffer and you can work with the
> files from there.
>
> The Q command should accept multi line blocks as long as you can find
> a regexp to do it. If not, maybe you want to write a small helper
> elisp function.

Beautiful! Emacs can do it out of the box without loading any further
resources. Here is what I did combining this problem with the one in the
other thread about replacing text in the html <column_right> block:

C-u [actual numeric argument not needed] C-x d  [here modify the ls
switches to make them read -IR as per Mathias] [specify parent of all
sub-directories of interest; files in this parent directory containing
matches to regexp will be processed too.] %g someregexp* Q sameregexp [a
buffer is opened for each file in parent and in all subdirectories
containing match(es) to regexp and the process works exactly as in C-M-%.

* In the block search-replace example you could use: (not tested but I
think the middle pair of escaped parentheses will be interpreted as
grouping rather than as matched substring for later reference by \1 \2)

 \(<starttextpattern>\)\(.\|^J\)*?\(<endtextpattern>\) RET
\1<replacementtext>\2 RET  ;; search-replace arbitary text bracketed by
start- and endpattern.  ^J is input with C-qC-j
[Thanks to Florian Kaufman for this. Now I understand non-greedy operators
better.]

Ed

^ permalink raw reply	[flat|nested] 10+ 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; 10+ 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] 10+ messages in thread

* Re: regexp question
  2006-09-29 22:03         ` Dieter Wilhelm
@ 2006-09-30  8:53           ` Peter Dyballa
  0 siblings, 0 replies; 10+ 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] 10+ messages in thread

end of thread, other threads:[~2006-09-30  8:53 UTC | newest]

Thread overview: 10+ 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
     [not found] <mailman.7420.1159269539.9609.help-gnu-emacs@gnu.org>
2006-09-26 15:44 ` AW: replace a textblock in multiple files Mathias Dahl
2006-09-29  0:51   ` B. T. Raven
2006-09-27  3:36 ` Benjamin Rutt

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).