命令打印输出的行格式 [英] Command to print the output in a row format
本文介绍了命令打印输出的行格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在一排的格式输出以下打印到CSV文件。用awk或bash有人能帮帮我吗?
服务器abc.com
osbits 64
OSTYPE窗口
我要打印输出这样并转发到一个csv格式
abc.com的x64窗口
解决方案
有关输入
服务器abc.com foo.com bar.com buz.org
osbits 64 86 SPARC PPC
OSTYPE linux的窗户在solaris MAC
在awk脚本
{
对于(i = 1; I< = NF; ++ I)
一个[I] [NR] = $ I;
}
结束 {
为(ⅰ= 2; I&下; =长度(a)++ⅰ){
海峡= a [i] [1]
为(J = 2; J&下; =长度(一个由[i]); ++ j)条
海峡=海峡,A [I] [J]。
打印海峡
}
}
产生
abc.com,64位,Windows
foo.com,X86的Linux
bar.com,SPARC的Solaris
buz.org,PPC,MAC
I am trying to print the below output in a row format to a csv file. Can someone help me using awk or bash ?
Server abc.com
osbits x64
ostype windows
I want to print the output like this and forward to a csv format
abc.com x64 windows
解决方案
For the input
Server abc.com foo.com bar.com buz.org
osbits x64 x86 sparc ppc
ostype windows linux solaris mac
the awk script
{
for (i=1;i<=NF;++i)
a[i][NR] = $i;
}
END {
for (i=2;i<=length(a); ++i) {
str = a[i][1]
for (j=2; j<=length(a[i]); ++j)
str = str "," a[i][j]
print str
}
}
produces
abc.com,x64,windows
foo.com,x86,linux
bar.com,sparc,solaris
buz.org,ppc,mac
这篇关于命令打印输出的行格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文