Я не знаю, как создать автономный двоичный файл с использованием AWK. Однако, если вам нравится AWK, вполне вероятно, что вам понравится Python, и есть несколько способов создать автономную программу на Python. Например, Py2Exe .
Вот краткий пример Python:
# comments are introduced by '#', same as AWK
import re # make regular expressions available
import sys # system stuff like args or stdin
# read from specified file, else read standard input
if len(sys.argv) == 2:
f = open(sys.argv[1])
else:
f = sys.stdin
# Compile some regular expressions to use later.
# You don't have to pre-compile, but it's more efficient.
pat0 = re.compile("regexp_pattern_goes_here")
pat1 = re.compile("some_other_regexp_here")
# for loop to read input lines.
# This assumes you want normal line separation.
# If you want lines split on some other character, you would
# have to split the input yourself (which isn't hard).
# I can't remember ever changing the line separator in my AWK code...
for line in f:
FS = None # default: split on whitespace
# change FS to some other string to change field sep
words = line.split(FS)
if pat0.search(line):
# handle the pat0 match case
elif pat1.search(line):
# handle the pat1 match case
elif words[0].lower() == "the":
# handle the case where the first word is "the"
else:
for word in words:
# do something with words
Не то же самое, что AWK, но прост в изучении и на самом деле более мощный, чем AWK (язык имеет больше функций и множество «модулей» для импорта и использования). Python не имеет ничего неявного, например
/pattern_goes_here/ {
# code goes here
}
функция в AWK, но вы можете просто иметь цепочку if / elif / elif / else с соответствующими шаблонами.