awk搜索字符串并设置退出代码(如果存在) [英] awk search for string and set exit code if it exists

查看:134
本文介绍了awk搜索字符串并设置退出代码(如果存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查两个地址之间是否存在一行,如果存在则返回退出代码0,如果不存在则返回1.我想我有一个可行的例子,但是我想知道是否有更干净的方法可以做到.或RedHat上也常见的其他工具.

I want to check if a line exists between two addresses and return an exit code 0 if it exists and 1 if it does not. I think I've got one possible example working, but I'm wondering if there is a cleaner way to do it; or perhaps a different tool that's also common on RedHat.

我的命令:

awk 'BEGIN{found=1}NR==1,/^Match/{ if ( $0 == "PermitRootLogin yes" ) \
    { found=0 } }END { exit found }' /etc/ssh/sshd_config

推荐答案

awk '/^PermitRootLogin yes$/{f=1} /^Match/{exit} END{exit !f}' /etc/ssh/sshd_config

这篇关于awk搜索字符串并设置退出代码(如果存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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