Re: Help with a shell script

From: John L (jl_at_lammtarra.fslife.co.uk)
Date: 06/03/03

  • Next message: Shailesh Dargude: "Re: escaping '"
    Date: Tue, 3 Jun 2003 10:48:16 +0100
    
    

    "Darren" <dshelt1@foo.attbi.com> wrote in message news:slrnbdnr1l.h6n.dshelt1@foo.americredit.com...
    > I have about a years worth of text logs that have the following format:
    > (These are entries from my NOC posted into a custom perk/Tk app that
    > cannot be modified to change the output).
    >
    > +>05/21/03 00:00 - User1
    > Data warehouse loads are proceeding normally.
    >
    > +>05/21/03 00:01 - User1
    > All network services are currently available. AS/400 is currently
    > down for maintenance.
    >
    >
    > I need to change the entries in the file to be semicolon separated.
    > I have no problem getting the first line of each formatted properly,
    > as i can do that with sed or tr. What i am having difficulty doing
    > is moving the body of the entry up to the the same line as the date
    > and user info.
    >
    > My ideal output would look like this:
    > 05/21/03 00:00 ; User1 ; Data warehouse loads are proceeding normally.
    >
    >

    Since you are using sed, you can use the hold space to move
    everything onto the same line, until you hit a blank line,
    at which point you make your substitutions and print the line.
    So your sed command file will look something like this, but
    without my comments:

        H -- append pattern space to hold space
        /^$/ { -- for each blank line
            x -- exchange hold and pattern spaces
            s/xxx/yyy/ -- perform required substitutions
            p -- print pattern space
        }

    The substitutions are left to the OP, but there will need to be
    more than one of these commands, including one to get rid of
    the newlines -- s/\n//g -- but possibly after one of them has
    been changed to a semi-colon.

    This assumes the input log file has a blank line at the end (or
    the last entry will not be printed). This is easily fixed.

    John.


  • Next message: Shailesh Dargude: "Re: escaping '"

    Relevant Pages

    • Re: Help with a shell script
      ... >I have about a years worth of text logs that have the following format: ... >I need to change the entries in the file to be semicolon separated. ... >My ideal output would look like this: ...
      (comp.unix.shell)
    • Re: Help with a shell script
      ... > I have about a years worth of text logs that have the following format: ... > (These are entries from my NOC posted into a custom perk/Tk app that ...
      (comp.unix.shell)
    • Re: Output to txt:
      ... Then to follow, are all the entries ... : column entry. ... To get around this for now, I format the output as html ... Word stores a file with embedded code to display it as it is seen on screen ...
      (microsoft.public.scripting.vbscript)
    • Re: Need help with import *.ldf
      ... An import file will not use the same format as an exported file will. ... The only time you use the changetype of add is when you are ... changetype: modify ... removes all of your old entries. ...
      (microsoft.public.exchange.admin)
    • Re: QDE (Quick Date Entry)
      ... > ambiguous entries interpretted. ... I'm with you that an *individual* user has his format and sticks to it. ... > functionality just ain't that complicated. ... What one can argue about is if using ...
      (microsoft.public.excel.worksheet.functions)