我正在使用一个调用 awk
的脚本与 -i inplace
Web 应用程序内的扩展(在 Debian 9
上)。在真实服务器 ( centOS 7
) 上部署应用程序时,它会失败,原因是 awk
/gawk
无法识别-i inplace
输入。
示例:
example.txt
one 1
two 2
three 3
尝试时:
awk -i inplace -F'\t' '{if ($1 == "two") print "four","4"; else print $0}' example.txt
输出错误:
Usage: gawk [POSIX or GNU style options] -f progfile [--] file ...
Usage: gawk [POSIX or GNU style options] [--] 'program' file ...
POSIX options: GNU long options: (standard)
-f progfile --file=progfile
-F fs --field-separator=fs
-v var=val --assign=var=val
Short options: GNU long options: (extensions)
-b --characters-as-bytes
-c --traditional
-C --copyright
-d[file] --dump-variables[=file]
-e 'program-text' --source='program-text'
-E file --exec=file
-g --gen-pot
-h --help
-L [fatal] --lint[=fatal]
-n --non-decimal-data
-N --use-lc-numeric
-O --optimize
-p[file] --profile[=file]
-P --posix
-r --re-interval
-S --sandbox
-t --lint-old
-V --version
To report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.
gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.
Examples:
gawk '{ sum += $1 }; END { print sum }' file
gawk -F: '{ print $1 }' /etc/passwd
我真的需要awk
脚本来完成 inplace
,我四处搜索并在网上搜索,但没有找到明确的解决方案,有人知道如何使其工作吗?
提前非常感谢您的帮助
最佳答案
正如 hek2mgl 提到的,如果你的 awk
没有就地选项,你可以尝试一下。
awk .....your code....Input_file > temp_file && mv temp_file Input_file
关于linux - awk 在 centOS 7 上就位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57701681/