UNIX(AIX)脚本,仅使用awk或其他文件处理实用程序来处理文件 [英] UNIX(AIX) script to process a file using only awk or other file processing utilities

查看:150
本文介绍了UNIX(AIX)脚本,仅使用awk或其他文件处理实用程序来处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个任务要编写一个脚本,该脚本将过滤来自MQ runmqsc命令的输入并将输出重定向到另一个文件。我一直在尝试使用许多其他管道命令一起使用的Linux命令,在Linux中它似乎工作正常,但是我的管理器需要在AIX系统(即UNIX操作系统)上运行脚本。
我意识到许多在Linux上运行良好或在Linux上完成工作的命令将在UNIX或基于UNIX的系统上产生完全不同的输出。
runmqsc命令的输出如下所示:

I have a task to write a script that will filter an input from an MQ runmqsc command and redirect the output into another file. I have been working around using many other Linux commands piped together and it seems to work just fine in Linux, but my manager needs to run the script on an AIX system, so UNIX operating system. I was made aware that many commands that run fine on Linux or get the job done in Linux will produce a totally different output on UNIX or UNIX-based systems. The output from the runmqsc command looks like this:

5724-H72 (C) Copyright IBM Corp. 1994, 2009.  ALL RIGHTS RESERVED.
Starting MQSC for queue manager CNUMQ02B.


     1 : DISPLAY QLOCAL(*) CURDEPTH
AMQ8409: Display Queue details.
   QUEUE(ADEXA.AOM.REPLY.MR.QL)            TYPE(QLOCAL)
   CURDEPTH(0)                          
AMQ8409: Display Queue details.
   QUEUE(ADEXA.AOM.REPLY.QL)               TYPE(QLOCAL)
   CURDEPTH(0)                          
AMQ8409: Display Queue details.
   QUEUE(ADEXA.ERROR.QL)                   TYPE(QLOCAL)
   CURDEPTH(0)                          
AMQ8409: Display Queue details.
   QUEUE(ADEXA.FACT.OUT.QL)                TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409: Display Queue details.
   QUEUE(ADW.REMAN.XREF.ERR.QL)            TYPE(QLOCAL)
   CURDEPTH(14)
AMQ8409: Display Queue details.
   QUEUE(SAPNA.MESS.CRITICAL.CLASS.RESUME.QL)
   TYPE(QLOCAL)                            CURDEPTH(123)
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.

我基本上需要做的只是显示队列名称,空格,然后显示队列深度在同一行上,在文件的开头或结尾没有尾随空格,也没有换行符,因此它将类似于一个以空格为分隔符的csv文件。我还需要过滤出队列深度等于0的队列,因此输出将如下所示:

What I basically need to do is only display the name of the queue, a whitespace, and then the queue depth on the same line, with no trailing whitespaces and no newline characters at the beginning or end of file, so that it will resemble a csv file with the whitespace as the separator. I also need to filter out queues that have a queue depth equal to 0, so the output will look like this:

ADW.REMAN.XREF.ERR.QL 14

我说过我在Linux上尝试了许多命令,但是缺乏对什么命令和标志在UNIX和Linux上实际上或多或少相同的知识,而我的经理今天想要这样做,因此,如果有任何机会阅读此书,我要求您至少指导我尝试使用什么来工作出来:)谢谢。

As I said I tried many commands on Linux, but I have a lack of knowledge of what commands and flags actually work more or less the same on UNIX and Linux, and my manager wants this today, so if by any chance you read this I ask that you at least guide me what to use to try working it out :) Thanks.

这是我在Linux中写的:

This is what I wrote in Linux:

head -n -3 "$1" | 
tail -n +6 | 
sed '/AMQ8409: Display Queue details./d' | 
sed 's/TYPE(QLOCAL)//g' | 
tr -d ' \t\r\f' | 
awk 'NR%2{printf "%s ",$0;next;}1' | 
sed '/CURDEPTH(0)/d' | 
awk '{gsub(/QUEUE(/, ""); gsub(/CURDEPTH(/, ""); gsub(/)/, ""); print}' |
sort -nk2 


推荐答案

尝试以下简单命令。.

sed -n -e 's/.*QUEUE(\([^)]*\)).*/\1/p' -e 's/.*CURDEPTH(\([0-9]*\)).*/\1/p' \
   | paste -d ' ' - - \
   | grep -v ' 0$'

这篇关于UNIX(AIX)脚本,仅使用awk或其他文件处理实用程序来处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆