如何使用shell脚本创建csv文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用shell脚本创建csv文件相关的知识,希望对你有一定的参考价值。
我目前的输出是:
echo "Time Taken to checkout svn repository repo_performance hosted on $host on `date` is : $Time_checkout seconds" >> log.csv
echo "Time Taken to add $loopmax 10MB svn files in svn repository repo_performance hosted on $host `date` is : $Time_add seconds" >> log.csv
echo "Time Taken to commit $loopmax 10MB svn files in svn repository repo_performance hosted on $host on `date` is : $Time_commit seconds" >> log.csv
但是,我想创建一个csv文件,其中包含Host,Date,Operation,Duration及其值。
如何使用脚本编写它?
答案
你可以尝试这样的事情;
printf "Host Date Operation Duration
" >> log.csv
printf "$host $(date) Time Taken to checkout $Time_checkout
" >> log.csv
printf "$host $(date) Time Taken to add $loopmax 10MB svn files $Time_add
" >> log.csv
printf "$host $(date) Time Taken to commit $loopmax 10MB svn files $Time_commit
" >> log.csv
另一答案
你可以这样做:
echo "$host, `date`, checkout,$Time_checkout" >> log.csv
echo "$host, `date`, add, $Time_add" >> log.csv
echo "$host, `date`, cimmit, $Time_commits" >> log.csv
以上是关于如何使用shell脚本创建csv文件的主要内容,如果未能解决你的问题,请参考以下文章
如何通过读取shell脚本中的csv文件来将2列的总和添加到新列中