I know that {aigles awk bakunin cfaj futurelet ghostdog74 radoulov summer_cherry vgersh99 Ygor} among others post awk code. Often the code is clever, but it takes me a while to understand it because my thought processes are not exactly like those of the author. If it were to be in a standard format then perhaps the intent and method would be made more clear.
I'm posting this at unix.com because it seems to be the place that has the most awk action.
There is an awkpretty at awk tools , but it's not trivial to install (i.e. I tried it and failed, modified a few items, installed it, but it will not run past a certain point -- you're probably better at recognizing the problem(s) with it than I am, so you're welcome to try your hand at it if you wish). It has the advantage of being very general. As I understand it, it used the awk interpreter's parser, but a potential drawback of that is then it might not recognize all the {g, n, m, other}awk extensions.
Would an awktidy be useful for others?
Do you know of any such codes?
What would be some useful features for you in such a code? ... cheers, drl
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
Thanks for the pointers and comments.
I looked at gawk's --profile option suggested by radoulov. Although well-hidden, and a non-intuitive place in which to put a tidy option, it did seem to work quite well, especially when dealing with operator-operand separation. Mainly I want code to be output that can be used. However, the HTML conversion mentioned by Ygor could be useful for display purposes.
That being said, I found the following drawbacks to gawk's pretty-printing:
1) the code is not really ready for replacing into a script because of the TABs that are inserted,
2) most awk scripts (at least those that I write and use) are embedded into shell scripts. The gawk processor doesn't take kindly to such situations,
3) the coding is very loose; too loose even for me,
So I wrote some code to deal with these issues. Here is a sample of code flowing through this pipeline of processes:
from beginning to end:
I consider this to be a good start, but the extra passes have a number of drawbacks. This works in most of the cases I have thrown at it, but it's still alpha-level code. I don't know if I will put in the time to make it a public tool or not. The extra passes are written in perl ... cheers, drl