Skip to Content.
Sympa Menu

sm-sorcery - Re: [SM-Sorcery]questions about advanced file manipulation with bash/unix tools.

sm-sorcery AT lists.ibiblio.org

Subject: Discussion of Sorcery related topics

List archive

Chronological Thread  
  • From: George Mochrie <geo AT drasil.no-ip.org>
  • To: "Nicholas K. Jennings" <nkj AT namodn.com>, sm-sorcery AT lists.ibiblio.org
  • Subject: Re: [SM-Sorcery]questions about advanced file manipulation with bash/unix tools.
  • Date: Fri, 2 Aug 2002 17:00:41 +0100

hi

i've been doing something similar myself recently, although i only needed to
perform the edit on one line. afaik all u need is sed (wasn't there a song
about that ? :) .

u can use a couple of regexps to flag the start and end lines like this:

/<pattern1>/,/<pattern2>/

and the 'c' sed command will then substitute the text you want. so this sed
script _should_ replace text between lines starting with 'BEGIN' and 'END'
with the text 'this is a code block', one word per line:

/^BEGIN/,/^END/c\
this\
is\
a\
code\
block

i have not tested this tho, as i say i only needed to do the edit on one
line.
personally i use 'Linux in a Nutshell' from O'Reilly as my oracle.

best of luck, i'd be interested to know if my suggestion works.

On Wednesday 31 July 2002 5:23 am, Nicholas K. Jennings wrote:
> Hi all,
>
> I have some questions about how to go about doing some advanced file
> editing with bash script and the standard unix tools. Everytime I
> think about how to go about things I get caught up in the perl way
> to do it :)
>
> What I'd like to do is, edit a file, search for a section in that
> file, remove the whole section (several lines), which means being
> able to determin when the section starts, and ends (character
> recognition/regexp?). Then replace that section (in the same
> location) with generated content that I would have already
> generated to replace it.
>
> What tools would be needed to go about doing this? Any pointers,
> tips, examples etc. would be greatly appreciated.

--
George Mochrie
aka Drasil
ICQ# 84423409




Archive powered by MHonArc 2.6.24.

Top of Page