What must not be in an AWK script?
I am asking as I don’t find any tool to debug an AWK script. I have a script taking a lot of CPU so I need to know if I am doing something terribly wrong with the script.
Just for an example, I keep looking for output of a logfile via ‘tail -f filename’ till my script gets killed.
awkdb has not been updated since 2000. It has some limitations as well according to the web site. If you are using gawk, and look at its man page reference, you can see some options, like
--profile,--optimize,--dump-variables, etc. You can try those options. Another option is to use pgawk as indicated in the man page as well.Generally, if your script is slow in execution, either you have a REALLY large file, or your algorithm is causing the problem. You should at least show the code that you think is hogging up the CPU. Some of the things you should avoid doing if possible, for example
Calling the big file a 2nd (or more files)
awk ‘{}’ file file
Iterating a file with a while.
Loop as you iterate a file
awk ‘{while(( getline line<“file2”) >0 ) {} )}’ file
Storing values into arrays for a
big file takes up memory. Try to
clear some of the elements (or
delete the array) if not in use
anymore.