bash处理csv&gunplot画图过程

读取指定行指定列数据

记得清空文件

cat /dev/null > rate_fillrandom.csv

第一行写入新的文件

head -n1 rate.csv >> /tmp/test.csv

从第二行开始

compaction_second=`tail -n+2 compaction.csv`
cat compaction.csv | awk 'NR>1' | while read line
do

done

读取指定列

Time=`echo $line |awk '{print $1}'`
#读取第一列,文件从前面传过来
write_bandwidth=`cat compaction.csv | awk '{print $2}'`
#读取第二列,嘻嘻

连续的指定列

write_bandwidth=`cat compaction.csv | awk '{print $2,$3}'`

指定分割符为逗号

write_bandwidth=`cat compaction.csv | awk -F',' '{print $2,$3}'`

读取指定行的指定列

Time_1st=`head -n2 compaction.csv | tail -n1 | awk '{print $1}'`
#两个都可以
#head -n2 表示从第二行开始,往下的所有行.tail,表示从下面数第一行
tail -n+2 #表示整着数第二行往后.
Time_1st=`awk 'NR==2{print $1}' ./compaction.csv`

求最大值

cat data|awk 'BEGIN{ max = 0} {if ($1 > max) max = $1; fi} END{printf "Max = %.1f\n",max}'

求最小值

cat data|awk 'BEGIN{min = 65535} {if ($1 < min) min = $1;fi} END{printf "Min = %.1f\n",min}'

画图

时间转换成整数

Time=`date -d "$first_line_ts" +%s%6N`




# if(!exists("filename")) {
#   print "filename not exists"
#     exit
# }


if(!exists("output_name")) { 
  print "output_name not exists"
  exit
}

# set term gif animate delay 10 size 600,400 #设置图片大小以及间隔时间
set terminal svg size 800,400
# set autoscale xy

#set title 'rate_fillrandom'  #标题

#set output "rate_fillrandom.svg" #文件名


# gnuplot <<EOF
set key right
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.9
set output output_name
set xlabel '绝对时间'  #横坐标
set ylabel "Random load throughput(MB/s)" #纵坐标
set y2label "compaction time(micros)" #纵坐标2
set title "compaction time and throughput" #图片标题
set size 1,1 #缩放比例
#set xticks(x, calendar.month_name[1:13],color='blue',rotation=60)  #参数x空值X轴的间隔,第二个参数控制每个间隔显示的文本,后面两个参数控制标签的颜色和旋转角度,用来设置刻度

#set xrange[0:65536] #x范围
#set yrange[1:25] #y范围
#set xrange autoscale
# set key autotitle columnhead
set yrange [0:34]
set y2range [1532346:26803248]
set ytics nomirror
set y2tics

###########################正确的

plot "./data/compaction_copy.csv" using 1:2 axes x1y1  w l title "Cumulative_writes",\
     "./data/compaction_copy.csv" using 1:3 axes x1y1  w l title "Interval_writes",\
     "./data/compaction_time_copy.csv" using 1:2 axes x1y2 w l title "compaction_time_micros",\
     "./data/compaction_time_copy.csv" using 1:3 axes x1y2  w l title "compaction_time_cpu_micros"

###########################正确的






# plot "./data/compaction_copy.csv" using 1:2 axes x1y1 t "y1"  w l title "Cumulative_writes",\
#      "./data/compaction_copy.csv" using 1:3 axes x1y1 t "y1" w l title "Interval_writes",\
#      "./data/compaction_time_copy.csv" using 1:2 axes x1y2 t "y2" w l title "compaction_time_micros"
# set out
#load 'loop_sinx.plt' #循环画图的文件

# EOF
# plot for [col=2:6] filename using col:xtic(1) 
# #set output #导出


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值