I staked out over the years for AWK to work under the windows. There are problems with citation and route restrictions. My final solution is to βlet AWK fly for free,β which is command line free. I understand that it was designed as glue for the unix style juju command line, but I just wanted to use it as a scripting language.
All of my AWK scripts contain a list of goals and a specific output file. They can be launched by double-clicking on the associated DOS batch file:
: AWK.BAT - place in the same directory as GAWK @echo off :Check %1 in not null If [%1]==[] ( cls Echo No parameters passed goto End ) : Change to the parameter file location cd /D "%~dp1" : Set PrintFile - this will be the name of the script (not the target file) with ".out" Set PrintFile=%~nx1.out :Run AWK : -v PrintFile to allow renaming of output file : -f ScriptFile.awk the program : > Redirects output to a known destination cls P:\MyPrograms\EDITORS\Addins\gawk\gawk.exe -v PrintFile=%PrintFile% -f %* >%PrintFile% :End pause
The following is an example of my AWK scripts (extract all the lines using the :: tab and print them):
# AWK Template BEGIN{ ## Hard Code Target Files - Unix paths with / separators ## # Realtive paths from the location of ScriptFileName.awk # These will be added to the end of the ARG array - after any command line target files AddTarget("../APEdit.ahk") ## Hard Code Output Files - WinDos paths with \\ separators ## # Realtive paths from the location of ScriptFileName.awk # Default is ScriptFileName.awk.out passed in as a variable called PrintFile # PrintFile will be copied to OutputFile after processing using the END section OutputFile = "Keys.txt" # Set input record sep and field sep RS="\n" FS=" " # Set output RS and FS ORS="\n" OFS=" " # Write a header print "Key assignments from the source code" print " " } ## MIDDLE - Once per matching record! ## # Find autohotkey key definitions /::\t/ { print $0 } END{ ## Rename output files if (OutputFile) { system("Copy /Y " PrintFile " " OutputFile) } } ## Functions ## function AddTarget(FN){ # Need to check file exists if (FileExists(FN)){ ARGV[ARGC] = FN ARGC ++ } } function FileExists(FN) { if ((getline < FN) > 0) { close(FN); return 1 } else { print "Target file not found " FN > "error.awk.txt" return "" } }
You can see that this defines the purpose of the input in the script and determines the final purpose of the output in the script. It uses a temporary β.outβ file to avoid large print redirection by copying the file to the desired output in the END script section.
I have associated AWK files with this batch file and an option has been added in my editor to send AWK files to a batch file.
Yours faithfully
Gavin
source share