2017-04-20 44 views
0

我在一个文件中有原始PS命令输出,我想要找到如果发现了pmon,那么我需要像Oracle,数据库一样打印,如果Jboss发现需要打印像Jboss,Middle -ware。在unix中查找进程和打印应用程序名称

我有一个像下面

PMON,甲骨文数据库
的Jboss,JBoss和中间件
的Weblogic时,WebLogic,中间件映射文件。

我需要为此编写一个shell脚本,请你帮帮我。
感谢

回答

0

这样的事情,也许?:

$ cat foo 
pmon Oracle,Database 
jboss Jboss,Middle-ware 
weblogic Weblogic,Middle-ware. 
bash Bash,shell 

代码:

$ ps | awk ' 
BEGIN {       # hash the mapping file foo in the BEGINning: 
    while((getline < "foo") > 0) # read records from file 
     a[$1]=$2     # hash to a 
    close("foo") }    # be nice now and shut it up 
$NF in a { $0=$0 OFS a[$NF] }  # append mapping to the end of output 
1'        # print 
    PID TTY   TIME CMD 
4611 pts/3 00:00:04 bash Bash,shell 
15691 pts/3 00:00:00 ps 
15692 pts/3 00:00:00 awk 
31785 pts/3 00:00:00 emacs 

缺点:a[$1]=$2只允许一个单词映射,映射这样的:

emacs greatest entity's right hand 

会(呃,并不完全是这样吧d输出emacs greatest :)。

0

感谢Jamesh为您的时间。

我能够实现这个
同时读取线

txtgrep = echo $line | cut [email protected] -f1
txtappend = echo $line | cut [email protected] -f2

我已经修改了像
的JBoss @ JBoss的映射文件,中间件

相关问题