外壳输出对齐



如何对齐此脚本输出。

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是$实例的第六列。我该如何实现这一目标。我尝试了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

类似这样的东西:

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

awk-script的解释:

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

最新更新