使用粘贴命令将输出粘贴到bash中的CSV文件中 [英] Paste output into a CSV file in bash with paste command
问题描述
我正在使用以下粘贴命令:
I am using the paste command as below:
message+=$(paste <(echo "${arr[0]}") <(echo "$starttimeF") <(echo "$ttime") <(echo "$time") | column -t)
echo "$message"
它给了我以下输出:
ASPPPLD121 11:45:00 00:00:16 00:02:23
FPASDDF123 11:45:00 00:00:16 00:02:23
ZWASD77F0D 09:04:58 02:40:18 03:51:10
DDPADSDSD5 11:29:41 00:15:35 01:17:33
如何将其重定向到CSV或EXCEL文件?
How do I redirect this to a CSV or an EXCEL FILE?
OR
如何将其放入HTML表中?
How do I put it into HTML table?
推荐答案
您有三个问题.最容易解决的是CSV文件输出:
You have three questions in one. The easiest to solve is the CSV file output:
echo $message | awk 'BEGIN{OFS=","}{$1=$1}1' > mycsvfile.csv
这也将在excel中打开,因为excel可以读取csv文件,所以也许可以解决第二个问题?
This will also open in excel since excel can read csv files, so maybe that solves the second question?
Awk正在打开文件并逐行读取.我们将OFS(输出字段分隔符)设置为逗号.然后,我们仅将一个字段设置为等于其自身,这只是使awk处理记录并将其将结果打印输出到CSV文件的一种技巧.
Awk is opening the file and reading line by line. We set the OFS (Output Field Seperator) to a comma. Then we just set one of the fields equal to itself, which is a just a trick to get awk to process the record, and let it print out the results to the CSV file.
我想您也可以使用awk打印出HTML表,但这似乎是一种粗略的处理方式:
I suppose you could use awk to print out a HTML table too, but it seems like a gross way of doing things:
echo $message | awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}'