I'm in the process of moving a web site for a friend. The site has
over 100 files. There is a chunk/paragraph of code that needs to
replaced in each. The various search and replace tools I have seen
focus on one line strings. Is there a tool that would allow you in
a non cumbersome way to specify an entire "paragraph" to be searched
and replaced on?
Thanks in advance for any info
You probably want to use a set of ed commands to do this.
ed *.txt < commands.ed
Do the line breaks within the paragraph fall in the same place? Are the
original paragraphs all identical? What about the replacements?
The editor will probably do what you want, whatever the case.
Mark.
--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/
I think the embedded markup will be a bitch to work around.
If the paragraphs are all identical in content, it might be a little
easier to delete all the paragraphs and use SSI to pull in a single copy
of the paragraph from a file.
Jonesy
Awk may be able to do it. How do you define a paragraph in this
context? Is it a series of lines separated by a blank line? A block of
code in braces, where you have to count the left and right braces, not
including those that are quoted or commented?
> Hi;
Hi.
Awk. As someone mentioned, awk can help. Look for the "RS" (Record Separator)
builtin var.
Perl. Look for the $/ ($RS, $INPUT_RECORD_SEPARATOR) builtin var.
Shell. Possibly setting IFS to something like
IFS="
"
might help, but I haven't checked (and it won't handle more than two
empty lines).
You can also do some horrible solutions, like replace the eol char and
the first char in the next line with something "string-doesnt-exist_$x".
Then when done, replace "string-doesnt-exist_$x" with "\n$x".
For this, you need perl or something like that. Once you do this
conversion, you can use line oriented programs to do your massage.
Vilmos
Maybe I am totally off the mark but wouldn't a diff+patch solve this
automatically? Just a thought. Perhaps I misunderstand your problem.
--
Rahul
Rahul <nos...@invalid.invalid> wrote:
> Maybe I am totally off the mark but wouldn't a diff+patch solve this
> automatically? Just a thought. Perhaps I misunderstand your problem.
Another thought is to use perl to slurp in each page in one go, and
match the start/end of the paragraph (i.e. ignoring line breaks) for
the substitution. Pretty much a one-liner I would have thought:
perl -i.bak -e 'local $/; $page = <>; $page =~ s/^Start of para .*? to
its end$/replacement text/m; print $page' *.html
(Untested)
Chris