linux - awk 在 centOS 7 上就位

标签 linux awk centos centos7

我正在使用一个调用 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/

相关文章:

python - 无法导入模块 'lambda_function' : No module named '_speech_py_impl'

linux - solaris elfedit : Is there something similar for linux ?(共享库编辑器)?

c# - .net core docker centos HttpRequest错误: (Socket Exception) Resource temporarily unavailable

apache - (13)Permission denied : access to/wsgi denied, mod_wsgi, CentOs

centos - Openstack - 更改仪表板的管理员密码

java - 如何将 JButton 添加到 Canvas()?或者如何将 JButton 添加到 Panel() 并使 Panel() 背景透明?

linux - 从内核线程为用户空间分配内存

shell - 减去相应的行

bash - 从文件中读取行,在第二个文件中进行 grep,并为每个 $line 输出一个文件

linux - 仅使用 awk 或其他文件处理实用程序处理文件的 UNIX(AIX) 脚本