我写的第一个shell(解析文件并绘制图形)

#! /bin/bash
#mem.sh
echo "Being parsed files, please wait......"
#delete file filename.dat for next shell operator...
rm *.dat
export temp=0
export i=0
export j=0
export z=0
export SUM="0"
export file_node_max=0
export file_num=0
export filename="file""$file_num"".dat"


temp1=0
s=0
node_min[$file_num]=0
node_count[$file_num]=0


for name in `echo thread_mem*`
do
# global variables
SUM="0"
i=0
if [ $j -ge $1 ]
then
let "file_num+=1"
filename="file""$file_num"".dat"
j=0
z=0
node_count[$file_num]=0
node_min[$file_num]=0
fi


let "file_node_max=0"


# loop read each lines
while read line
do
# echo $line
TEMP=`echo $line | awk -F": " '{print $2}'`
# echo $TEMP


VAL=`echo $TEMP | awk '{print $1}'`
# echo $VAL


if [ "$VAL" = "trace" ]
then
let "file_node_max+=1"   
if [ $i -eq 0 ]
then
echo -n "$name " >> $filename # no change line  -n 
i=$[$i+1]
# z=$[$z+1]
else
let "SUM/=1024" # cause loss of accuracy
#            SUM=`echo "scale=3;$SUM / 1024"|bc`
#            SUM=`echo "scale=3;$SUM / 1024"|bc`
            #********************************
            if [ $z -eq 0 ]
            then
let "z+=1"
temp1=${node_min[$file_num]}
                node_min[$file_num]=$SUM
            else
                if [ ${node_min[$file_num]} -gt $SUM ]
                then
temp1=${node_min[$file_num]}
                    node_min[$file_num]=$SUM
# else
# echo "***********************************************************"
                fi
            fi
            #*******************************
echo -n "$SUM " >> $filename
SUM="0"
# SUM=0
i=$[$i+1]
fi
else
SUM=$[$VAL+$SUM]
# let "SUM+=VAL"
# echo $SUM
fi
done < $name       # match to while loop...
let "SUM/=1024" # cause loss of accuracy
# SUM=`echo "scale=3;$SUM / 1024"|bc`
# SUM=`echo "scale=3;$SUM / 1024"|bc`
echo "$SUM " >> $filename


    if [ $file_node_max -gt $2 ]
    then
       # sed -i '/$name/d' $filename
sed -i '$d' $filename
echo "$name " >> bigfile.dat
# let "j-=1"
bigfile_name[$s]="$name"
let "s+=1"
node_min[$file_num]=$temp1
continue
    fi


# *******************************************
    if [ ${node_min[$file_num]} -gt $SUM ]
    then
        node_min[$file_num]=$SUM
    fi
# *******************************************
# histogram max is file_node_max
if [ $file_node_max -gt ${node_count[$file_num]} ]
then
node_count[$file_num]=$file_node_max
fi
let "j+=1"
done   # match to for loop ...


echo "part_1 is sucessed !!!"
echo "Being resolved part_2,please waiting ......"
#echo "the number of analyse file: $file_num"


#for d in 0 1 2 3 4 5 6
#do
# echo ${node_count[$d]}
#done
#for e in 0 1 2 3 4 5 6
#do
# echo ${node_min[$e]}
#done 
#for f in 0 1 2 3
#do
# echo ${bigfile_name[$f]}
#done


# zhun bei
for((i=0;i<=$file_num;i++))
do
cmd_prefix="plot ""\"file${i}.dat\" using 2:xticlabels(1)"
for((j=2;j <= ${node_count[$i]};j++))
do
t=$[$j+1]
cmd_prefix=$cmd_prefix",''using ${t}"
done
plot_cmd[$i]=$cmd_prefix
# echo ${plot_cmd[$i]}
done


for((i=0;i<=$file_num;i++))
do
# if [ ${node_min[$i]} -gt 1024 ]
# then
# node_min[$i]=`expr ${node_min[$i]} / 1024`
node_min[$i]=`expr ${node_min[$i]} - 5`
# let "${node_min[$i]}-=5"
# if [ ${node_min[$i]} -gt 1024 ]
# then
# node_min[$i]=`expr ${node_min[$i]} / 1024`
# fi
# fi
# echo ${node_min[$i]}
done
#echo "****************  Gnuplot  **********************"
for((i=0;i<=$file_num;i++))
do
echo "
    set style data histogram
    set style histogram clustered gap 10
    set style fill solid 1.00 border -1
    set terminal gif
    set output 'file${i}.gif'
set title 'Kingbase'
unset key
set xtic rotate
set format y \"%.3g KB\"
set yrange [${node_min[$i]}:]
${plot_cmd[$i]}
    " | gnuplot
done


# big file process


for((i=0;i<$s;i++))
do
j=0
total=0
count=1
while read line
do
bt=`echo $line | awk -F": " '{print $2}'`
var=`echo $bt | awk '{print $1}'`
# echo $var
if [ "$var" = "trace" ]
then
if [ $j -eq 0 ]
then
let "j+=1"
echo -n "${bigfile_name[$i]} " >> "bfile""$i"".dat"
else
let "total/=1024"
echo -n "$total " >> "bfile""$i"".dat"
let "count+=1"
total=0
fi
else
total=$[$var+$total]
# echo "$total"
fi
done < ${bigfile_name[$i]}
let "total/=1024"
echo "$total" >> "bfile""$i"".dat"
bigfile_node_max[$i]=$count
done




for((i=0;i<$s;i++))
do
bf_prefix="plot ""\"bfile${i}.dat\" using 2:xticlabels(1)"
for((j=2;j<=${bigfile_node_max[$i]};j++))
do
t=$[$j+1]
bf_prefix=$bf_prefix",''using ${t}"
done
plot_cmd_bfile[$i]=$bf_prefix
done
# ***************** gnuplot big file *****************
for((i=0;i<$s;i++))
do
echo "
    set style data histogram
    set style histogram clustered gap 10
    set style fill solid 1.00 border -1
    set terminal gif
    set output 'bfile${i}.gif'
set title 'Kingbase'
unset key
set xtic rotate
set format y \"%.3g KB\"
set yrange [0:]
${plot_cmd_bfile[$i]}
    " | gnuplot
done
echo "All File successfully resolved"
# end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值