|
Home > Archive > Unix administration > March 2004 > text formatting question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
text formatting question
|
|
| cmiller0470@earthlink.net 2004-03-26, 11:46 am |
| Hello, all.
I've been lurking in this group for some time now, and have picked up
several helpful pointers from all of you. Thanks for that, and I'm
hoping you can maybe help me with a question of my own...
I have been tasked with taking a system log from one of my applications
and turning it into a human readable 'daily report,' to be sent out each
day via a cron job. I have no 'formal' UNIX training, per se, but have
learned much due to the assumption on the part of my employer that, since
I know what UNIX is, I must be some sort of guru on the subject.
Basically, they tossed the baby into the water, and hoped it could swim.
Well... I make no claims to be any sort of olympic athlete, but I
believe I've at least learned to do the backstroke :-)
Here's my question.
I am using 'grep' and 'grep -v' to filter out the events from the log
that I am interested in. I am using 'cut' to chop off the nasty bits at
the beginning and end of each line that I don't want to see. I am using
'tr 'xx' 'yy' ' and 'sed s/xx/yy/g' to further make the report more
readable. Basically, shove it down the pipeline, and trim one bit off at
a time.
Here's my question:
How the heck do I get the resulting information to line up in nice, neat
columns, such as a management type would like to see?????
TIA,
Chris
Asked here, Hope to see the answer(s) here.
| |
| Adam Price 2004-03-26, 11:46 am |
| On Fri, 26 Mar 2004 05:48:34 GMT, cmiller0470@earthlink.net wrote:
> Hello, all.
>
> I've been lurking in this group for some time now, and have picked up
> several helpful pointers from all of you. Thanks for that, and I'm
> hoping you can maybe help me with a question of my own...
>
>
> I have been tasked with taking a system log from one of my applications
> and turning it into a human readable 'daily report,' to be sent out each
> day via a cron job. I have no 'formal' UNIX training, per se, but have
> learned much due to the assumption on the part of my employer that, since
> I know what UNIX is, I must be some sort of guru on the subject.
> Basically, they tossed the baby into the water, and hoped it could swim.
>
> Well... I make no claims to be any sort of olympic athlete, but I
> believe I've at least learned to do the backstroke :-)
>
> Here's my question.
>
> I am using 'grep' and 'grep -v' to filter out the events from the log
> that I am interested in. I am using 'cut' to chop off the nasty bits at
> the beginning and end of each line that I don't want to see. I am using
> 'tr 'xx' 'yy' ' and 'sed s/xx/yy/g' to further make the report more
> readable. Basically, shove it down the pipeline, and trim one bit off at
> a time.
>
> Here's my question:
>
> How the heck do I get the resulting information to line up in nice, neat
> columns, such as a management type would like to see?????
>
> TIA,
>
> Chris
>
>
>
>
> Asked here, Hope to see the answer(s) here.
Seriously, this looks like the sort of job that PERL was made for.
I would be inclined to re-write the whole script in perl.
If you can't or don't want to do that then you can use printf to output
formatted strings.
Awk could also probably do most of what you want.
If you really want to make it management friendly, the you could output the
data comma separated and then feed in into a spreadsheet for them.
Or you could output html tables.
If you take the thing over to comp.unix.shell, give them the code you
already have and an example input and desired output then they will
undoubtedly help.
Adam Price
| |
|
| > Here's my question:
>
> How the heck do I get the resulting information to line up in nice, neat
> columns, such as a management type would like to see?????
>
You can do this with printf:
cra@fw018:/tmp $ cat data.txt
hj hhhh f 88
sajkld asjdf jj 12.5
asdf j j 108.12
cra@fw018:/tmp $ printf "%-12s %-6s %-6s %6.2f\n" `cat data.txt`
hj hhhh f 88.00
sajkld asjdf jj 12.50
asdf j j 108.12
It may take you some to understand the format strings described in
formats(5), but afterwards it's quite simple.
Regards
Christian Ramseyer
| |
| William Park 2004-03-26, 6:38 pm |
| cmiller0470@earthlink.net wrote:
> How the heck do I get the resulting information to line up in nice, neat
> columns, such as a management type would like to see?????
Post examples of what you have and what you want. Or, post to
alt.*
--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data processing and document management.
| |
|
| In article <Xns94B884AB77B3cmiller0470earthlink@207.69.154.201>,
cmiller0470@earthlink.net wrote:
[snip: creating reports from data]
>
> How the heck do I get the resulting information to line up in nice, neat
> columns, such as a management type would like to see?????
un*x has a lot of utilities to help you. Traditional ones include awk(1)
and printf(1)[0]. One of the reasons the language PERL got created is
creating nicely formatted reports.
I somehow thought you wanted to create _paper_ reports, for which also a
number of tools are available; from roff(1) and newer versions[1] to
even TeX[2], which is probably overkill. Even more overkill is to
massage the data into Docbook.
As you can see there are a lot of options, but as ObOtherPoster said,
for further tips you'd probably want to supply examples of what you have
and what you'd want.
[0] A command-line interface to printf(3), a C library function. You could
also write a program in C to generate reports, of course.
[1] nroff, troff, and groff I know of.
[2] And various macro packages to help use it, like LaTeX.
--
j p d (at) d s b (dot) t u d e l f t (dot) n l .
| |
| Ian Wilson 2004-03-29, 8:47 am |
| cmiller0470@earthlink.net wrote:
> Hello, all.
>
> I've been lurking in this group for some time now, and have picked up
> several helpful pointers from all of you. Thanks for that, and I'm
> hoping you can maybe help me with a question of my own...
>
>
> I have been tasked with taking a system log from one of my applications
> and turning it into a human readable 'daily report,' to be sent out each
> day via a cron job. I have no 'formal' UNIX training, per se, but have
> learned much due to the assumption on the part of my employer that, since
> I know what UNIX is, I must be some sort of guru on the subject.
> Basically, they tossed the baby into the water, and hoped it could swim.
>
> Well... I make no claims to be any sort of olympic athlete, but I
> believe I've at least learned to do the backstroke :-)
>
> Here's my question.
>
> I am using 'grep' and 'grep -v' to filter out the events from the log
> that I am interested in. I am using 'cut' to chop off the nasty bits at
> the beginning and end of each line that I don't want to see. I am using
> 'tr 'xx' 'yy' ' and 'sed s/xx/yy/g' to further make the report more
> readable. Basically, shove it down the pipeline, and trim one bit off at
> a time.
>
> Here's my question:
>
> How the heck do I get the resulting information to line up in nice, neat
> columns, such as a management type would like to see?????
>
>
> Asked here, Hope to see the answer(s) here.
I'd use seomething like:
fooreport.pl logfile [logfile2 ...] > foo.rep
where fooreport.pl is something like
#!/usr/bin/perl
while (<> ) { # read lines from log
next unless /something/; # like grep something
s/xx/yy/g; # sedlike
($this, $that, $other) = split; # not very awklike
write; # could printf instead
}
format STDOUT_TOP=
THIS THAT
------------------- --------------------
|
|
|
|
|