我有一个文件,它可能包含以下任何一个组合中的代码块。我需要检查文件中是否有“进口遥测”。
我的代码:
#!/bin/sh
if grep -Eq "import\s+telemetry" "./xyz.yang";
then
echo "This is a telemetry yang"
else
echo "This is a normal yang"
fi上述方法适用于1和2,但不适用于3。
我试过跟随,但它是贪婪的,并将匹配“进口之类的.遥测”以及。
if awk '/import/,/telemetry/' "./xyz.yang";有什么建议吗?
我的解决方案:
#!/bin/sh
if grep -Pzq 'import[ \n\r\t]+telemetry' './xyz.yang';
then
echo "This is a telemetry yang"
else
echo "This is a normal yang"
fi发布于 2019-04-09 14:44:59
向grep添加一个-z标志,它就能工作了。
#!/bin/sh
if grep -Eqz "import\s+telemetry" "./xyz.yang";
then
echo "This is a telemetry yang"
else
echo "This is a normal yang"
fihttps://stackoverflow.com/questions/55595269
复制相似问题