bash 如何使用shell脚本创建csv文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40175868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:26:32 来源:igfitidea点击:
How to create csv file using shell script
提问by devops
My output currently is:
我目前的输出是:
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
But, I want to create a csv file which has Host, Date, Operation, Duration and its values in the rows.
但是,我想创建一个 csv 文件,该文件在行中包含主机、日期、操作、持续时间及其值。
How can I make it using scripting ?
如何使用脚本编写它?
回答by Mustafa DOGRU
you can try something like this;
你可以尝试这样的事情;
printf "Host\tDate\tOperation\tDuration\n" >> log.csv
printf "$host\t$(date)\tTime Taken to checkout\t$Time_checkout\n" >> log.csv
printf "$host\t$(date)\tTime Taken to add $loopmax 10MB svn files\t$Time_add\n" >> log.csv
printf "$host\t$(date)\tTime Taken to commit $loopmax 10MB svn files\t$Time_commit\n" >> log.csv
回答by Hadrien Huvelle
You may just do:
你可以这样做:
echo "$host, `date`, checkout,$Time_checkout" >> log.csv
echo "$host, `date`, add, $Time_add" >> log.csv
echo "$host, `date`, cimmit, $Time_commits" >> log.csv