gpt4 book ai didi

bash - shell 脚本 : Use command in awk

转载 作者:行者123 更新时间:2023-11-29 09:47:51 24 4
gpt4 key购买 nike

这是我的代码

awk '{a[$1":"$5]}
END{for(i in a)
{
split(i,b,":");
split(b[2],c,"[");
print b[1],b[2]
}
}' /var/log/messages

输出将是:(显示月份和流程名称)

May init
May rhsmd
May kernal

我想将进程名称更改为简短描述。简短描述基于“man”文档。

这个命令帮助我打印我想要的东西。

man init | sed -n '6p' | cut -c 8-

输出:

init - Upstart process management daemon

最后,我找不到将“man”代码嵌入awk 的方法。以下是我预期的最终输出,我怎样才能做到这一点?谢谢。

May init - Upstart process management daemon
May rhsmd - A Program for querying the Red Hat Network for updates and information
May kernal

有一些/var/log/messages 的样本

May 21 03:30:02 redhat rhsmd: This system is registered to RHN Classic.
Sep 22 03:35:02 redhat rhsmd: This system is registered to RHN Classic.
May 22 13:00:31 redhat init: serial (hvc0) main process (1326) killed by TERM signal
May 22 13:00:31 redhat init: tty (/dev/tty6) main process (1336) killed by TERM signal
May 22 13:00:32 redhat rhnsd[1256]: Exiting

最佳答案

我会为此使用 shell。

awk '{a[$1":"$5]}
END{for(i in a)
{
split(i,b,":");
split(b[2],c,"[");
print b[1],b[2]
}
}' /var/log/messages |
while read month cmd; do
echo -n "$month "
whatis "$cmd"
done

关于bash - shell 脚本 : Use command in awk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23846423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com