1834695 Members
2369 Online
110069 Solutions
New Discussion

Re: script

 
Godfrey
New Member

script

I want to select mnemo,sens,qte,prix from the log file where Uti = 102. How to write that script? The output should look like.

uti = 102,
mnemo = 223 ,
sens = 0,
qte = 400000,
prix = 56.750000,
uti = 102,
mnemo = 210 ,
sens = 0,
qte = 400000,
prix = 56.800000,
5 REPLIES 5
Carsten Krege
Honored Contributor

Re: script

That is quick and dirty:

#!/sbin/sh

for i in `grep -n "uti = 102" logfile | cut -f1 -d:`
do
i=`expr $i + 13`
head -n $i logfilename | tail -13 |grep -e "uti =" /
-e mnemo -e sens -e qte -e prix
done

This assumes that one record is always 13 lines long. I bet you will see some nice awk scripts later. :)

Carsten
-------------------------------------------------------------------------------------------------
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. -- HhGttG
Andreas Voss
Honored Contributor

Re: script

Hi,

here my awk script :-)

awk -vUTI_SELECT=102 'BEGIN{valid=0;}
{
if($1 == "uti" && int($3) == UTI_SELECT)
valid=1;
if(valid == 1)
{
if($1 == "uti")
print $0;
else if($1 == "mnemo")
print $1 " " $2 " " $3 " " $4;
else if($1 == "sens")
print $0;
else if($1 == "qte")
print $0;
else if($1 == "prix")
{
print $0;
valid=0;
}
}
}'

Regards
Carlos Fernandez Riera
Honored Contributor

Re: script


I whish you like this:


sed -e 's/-/#/g
s/ //g
s/,/ /' file > file1

awk ' BEGIN{RS="#"} # set field separator to "#
#
length($0) >0 {
for (i=1; i {
printf "[ %s ]",$i
}
printf "\n" }' file1
unsupported
Vincenzo Restuccia
Honored Contributor

Re: script

#split -l 14 log.txt
#grep -l "uti = 102" x*
output is xaa,xac,etc.
#grep -E "uti|mnemo|sens|qte|prix" xaa|grep -v "uti_cmd"
#grep -E "uti|mnemo|sens|qte|prix" xac|grep -v "uti_cmd"
Ralph Grothe
Honored Contributor

Re: script

How about a line of Perl for a change? ;-)

# perl -e 'while (<>){print if /uti\s+=\s+102,/../Dval/}' /path/to/raw_data
Madness, thy name is system administration