I have a file that may contain the following block of code in any one of the combinations. I need to check for the presence of "import telemetry" in the file.
- import telemetry { prefix tm; }
- import telemetry { prefix tm; }
import
telemetry { prefix tm; }
My code:
#!/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
The above works for 1 and 2 but not for 3.
I tried following but it's greedy and will match "import blah blah blah.. telemetry " as well.
if awk '/import/,/telemetry/' "./xyz.yang";
Any suggestions?
My solution:
#!/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