Re: Help with a shell script
From: John L (jl_at_lammtarra.fslife.co.uk)
Date: 06/03/03
- Previous message: mike: "escaping '"
- In reply to: Darren: "Help with a shell script"
- Next in thread: Dr. Yuan LIU: "Re: Help with a shell script"
- Reply: Dr. Yuan LIU: "Re: Help with a shell script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
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.
- Previous message: mike: "escaping '"
- In reply to: Darren: "Help with a shell script"
- Next in thread: Dr. Yuan LIU: "Re: Help with a shell script"
- Reply: Dr. Yuan LIU: "Re: Help with a shell script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|