将unix输出发送到csv文件 [英] send the unix output to a csv file
本文介绍了将unix输出发送到csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将unix命令的输出数据放到一个csv文件中.假设我得到的输出是:
I want to put the output data from unix command to a csv file. Suppose the output which I am getting is :
A
B
C
我想将此数据作为
A B C
在三个不同的列中但在同一行中.
in three different columns but same row.
推荐答案
尝试一下:
printf '%s\n' A B C | paste -sd ' ' >> file.csv
或更经典的CSV(带有,
的分隔符:
or more classical for a CSV (delimiter with a ,
:
printf '%s\n' A B C | paste -sd ',' >> file.csv
printf'%s \ n'A B C
只是一个示例,具有与您相同的示例输入.我的解决方案也适用于同一行中的空格.
printf '%s\n' A B C
is just an example to have the same sample input as you. My solution works with spaces in a same line too.
EDIT ,您似乎需要使用 for
循环进行处理,因此:
EDIT from your comments, you seems to need to treat with a for
loop, so :
for i in {0..5}; do printf '%s\n' {A..C} | paste -sd " " >> file.csv; done
或使用伪代码:
for ...:
unix_command | paste -sd " " >> file.csv
endfor
这篇关于将unix输出发送到csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文