1832864 Members
2874 Online
110048 Solutions
New Discussion

newbie needs a script

 
hien
Occasional Advisor

newbie needs a script

hi guys, pardon me but im still a newbie. ill appreciate any help for this:

i have five log-files, say generation, deletion, filtering,sorting and summarizing. each of this logs contains 3 entries say for generation-log (generation a, b, c...), deletion (deletion a, b, c...) which are variable in length. i wana make a script that could collect the details from each log and integrated the details into file a, file b and file c. so the output files will then be, File a - contains generation a, deletion a, filtering a, sorting a and summarizing a logs.
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: newbie needs a script

grep a generation > a.log
grep a deletion >> a.log
grep a filtering >> a.log
grep a sorting >> a.log
grep a summarizing >> a.log

repeat for b, c, etc.

Pete

Pete
H.Merijn Brand (procura
Honored Contributor

Re: newbie needs a script

pete, com'on, you can do better than that! :)

grep -e a -e b -e c generation deletion filtering sorting ... > a.log
Enjoy, Have FUN! H.Merijn
Pete Randall
Outstanding Contributor

Re: newbie needs a script

Good point, Merijn. It's early yet - only one coffee so far.

Pete

Pete
hien
Occasional Advisor

Re: newbie needs a script

thanks guys but its not only one line..the format for the 5 logs are below, say generation log.

=========a==============
fasdfasdf asdfasdf
asf adf
asf
asdf
asdf
asfasdfasdf
asfasdfasdf
==>end of a
=========b==============
fasdfsadf
asf
asdf
asfsd
af
==>end of b
=========c==============
asdf
asdf
asfs
adf
harry d brown jr
Honored Contributor

Re: newbie needs a script

nibble,

What are you identifying as a "LOG" ?????????


live free or die
harry
Live Free or Die
hien
Occasional Advisor

Re: newbie needs a script

hi harry,

actually, its not a log. its an output of a program which we have to filter manually then integrate it to files as reports.

the raw output is usually combination of alpha numeric, with some details that we don't need. usually separted as:

file output 1

======generation a====
asf13asdf
asdf134
asdf12323...
=====end of generation a==

==generation b====
afasdf123123
asdfsadf13
asdfasdf...
==end of generation b===

the other outputs have more orless the same format.
with filtering/removing unwanted details, i have already created a script which mostly uses grep. i have a problem in intergarting them to final data. say, file A should contain output1 A, output2 A, output 3 A...
F. X. de Montgolfier
Valued Contributor

Re: newbie needs a script

Hi,

if the files all have the same size, you could use a script like this one (untested):

#! /usr/bin/ksh
>result.txt
let nl=`wc -l file1`
let i=1
while [ $i -le $nl ]
do
a= `head -n $i file1|tail -n 1`
b= `head -n $i file2|tail -n 1`
c= `head -n $i file3|tail -n 1`

echo $a $b $c >> result.txt
let i=$i+1
done

As I don't have access to my platform currently, I couldn't test this cript, but it should not be far from the wished result.
Of course, the head|tail part of the script means that you're reading nl*(nl+1)*2 lines, but that's, after all, still a polynomial algorithm ;-)

Cheers,

FiX
Jean-Louis Phelix
Honored Contributor

Re: newbie needs a script

hi,

You could also try a script like this one :

#!/usr/bin/sh
TASK=$1
shift
OUTFILE=$TASK.out
awk '
/=generation '$TASK'=/,/=end of generation '$TASK'=/
/=deletion '$TASK'=/,/=end of deletion '$TASK'=/' $* > $OUTFILE

You could of course use a more complex pattern to delimit begin and end of blocks ... It's really simple because awk use its default action (printing line) for every linesbetween patterns.

Regards.
It works for me (© Bill McNAMARA ...)
Jean-Louis Phelix
Honored Contributor

Re: newbie needs a script

I forgot to write that you should use this script with the task as first parameter followed by the output files list ...

Regards.
It works for me (© Bill McNAMARA ...)