how to remove block of text from file - Unix

This is a discussion on how to remove block of text from file - Unix ; Guys, I have a very large file that has this block of text somewhere in it. The block as a whole is unique in the file. I'd like to write a script to delete the following block. I am looking ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: how to remove block of text from file

  1. how to remove block of text from file

    Guys,

    I have a very large file that has this block of text somewhere in it.
    The block as a whole is unique in the file. I'd like to write a script
    to delete the following block. I am looking do this in a shell script
    of some kind.

    sample.txt contents
    -----------------------------
    // something comes before
    [[[[block below should be
    deleted]]]]
    Node-path: calc
    Node-action: add
    Node-kind: dir
    Content-length: 0
    [[[[block above should be
    deleted]]]]
    Node-path: calc
    Node-path: calc/trunk
    // something comes after
    EOF

    'Node-path: calc' is not a unique string as you can see, so I need to
    somehow iterate over every occurence of it and check to see if 'Node-
    action: add' is a string following that line. If it is, I know that's
    the block of text I should delete. Is this overly complicated...I am
    pulling my hair out trying to figure out how to do this...please, any
    help?

    /sqad


  2. Re: how to remove block of text from file

    On Mon, 29 Oct 2007 19:37:36 -0000, sqad wrote:
    > Guys,
    >
    > I have a very large file that has this block of text somewhere in it.
    > The block as a whole is unique in the file. I'd like to write a script
    > to delete the following block. I am looking do this in a shell script
    > of some kind.
    >
    > 'Node-path: calc' is not a unique string as you can see, so I need to
    > somehow iterate over every occurence of it and check to see if 'Node-
    > action: add' is a string following that line. If it is, I know that's
    > the block of text I should delete. Is this overly complicated...I am
    > pulling my hair out trying to figure out how to do this...please, any
    > help?


    In a nut shell:
    You open an input and output file.
    You read a line in, if it is 'Node-path: calc' then you read another line
    and if it is 'Node-action: add' then set a no_output flag.
    You continue reading until you see 'whatever is end of block', clear
    no_output flag and continue outputing whatever you read in.


  3. Re: how to remove block of text from file

    In <1193686656.638560.276450@e9g2000prf.googlegroups.c om> sqad writes:

    > I have a very large file that has this block of text somewhere in it.
    > The block as a whole is unique in the file. I'd like to write a script
    > to delete the following block. I am looking do this in a shell script
    > of some kind.


    > Node-path: calc
    > Node-action: add
    > Node-kind: dir
    > Content-length: 0


    Will the block always contain EXACTLY those four lines? Or can they
    be somewhat different?

    --
    John Gordon A is for Amy, who fell down the stairs
    gordon@panix.com B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"


+ Reply to Thread