2017-09-25 69 views
1

如何对齐此脚本输出。外壳输出对齐

for instance in `find /bxp/*/*/*/prod/*/apache_*/httpd/htdocs/ -type f -name status.txt` ; do 
echo "`hostname`: `ls -ltr | ${instance}` : `cat ${instance}`" 
done 

输出的样子:

r008abc, /bxp/xip/xip.pentaho-server_pentaho-server-assembly/pentaho.prod.jobengine/prod/xip.pentaho-server_web.partition_0.0.1/apache_5.3.3-2.2. 
26/httpd/htdocs/status.txt, Web server is disabled 

但是我想要的输出如:

r008abc| xip - xip.pentaho-server_web.partition_0.0.1 | Web server is disabled 

XIP - 不过是$实例的第二列 - xip.pentaho- server_web.partition_0.0.1是$实例的第6列。我怎样才能做到这一点。我尝试过awk命令,但没有帮助。你的建议表示赞赏。

命令我试过

for instance in `find /bxp/*/*/*/prod/*/apache_*/httpd/htdocs/ -type f -name status.txt` ; do 
echo "`hostname`: `"ls -ltr | awk -F '/' '{print $3}"' ${instance}` : `cat ${instance}`" 
done 

回答

0

像这样oneliner:

find /bxp/*/*/*/prod/*/apache_*/httpd/htdocs/ -type f -name status.txt | awk -F/ -v host=$(hostname) '{cmd="cat \047" $0 "\047"; if ((cmd | getline out) > 0){printf "%s| %s - %s | %s\n", host,$3, $7, out} close(cmd);}' 

AWK-脚本的说明:

awk -F/           # use/as field separator 
    -v host=$(hostname)       # set var host  
'{ 
    cmd="cat \047" $0 "\047"      # define cmd 
    if ((cmd | getline out) > 0)     # read output of cmd 
     printf "%s| %s - %s | %s\n",host,$3,$7,out; # print formatted result 
    close(cmd); 
}' 
+0

这只是Awesome..Thanks。我几个小时都在为此而头痛。 – Satte

+0

将输出更改为适当的列。 –

+0

是的,我已经完成了。谢谢 – Satte