shell script to verify brackets

sunilsagar
sunilsagar used Ask the Experts™
on
Hi ,

I am trying to write a shell script to verify if brackets are used correctly in a file . If there is some other format it should show invalid.

Below are the correct formats :

[sunil:/1/2]
[sagar:/1/2/3/4]

Incorrect formats may have format :
[sunil:/1/2]]
[[sagar:/1/2]
[[sunil:/1/2/3]]

Please advise .
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
if grep -qv "^\[[a-z].*[0-9]\]$" /path/to/your/file
then
      echo "File contains invalid characters"
fi

Open in new window

Tintin,
That is good, but it doesn't confirm if there are double brackets at the end.

Simplify it like this maybe:

if egrep '(\[\[|\]\])' /path/to/file
then
         echo "Invalid characters exist"
fi

Author

Commented:
Thanks for quick Savone, it works !

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial