views:

85

answers:

1

hi, i'm looking for script in awk which will check if it has proper bracket placing. used brackets are {} [] and () every bracket should be closed, and brackets can't be mixed, illegal example: ( [ ) ]

A: 

You'll have to read the file character-by-character. Build a stack of open brackets seen. When you see a close bracket, you can either pop the matching open bracket off the stack, or record an error that the brackets don't match.

awk's not the right tool for this job. I'd use a general purpose scripting language (Perl/Tcl/etc).

glenn jackman
unless you are talking about a module of some sort that does these kind of stuff, using awk is still one of the right tool if you are talking about pure file parsing. It won't lose to Perl or other scripting languages in this respect.
ghostdog74