-1

I'm using a script that calls awk with -i inplace extension inside a web app (on Debian 9). When deploying the app on the real server (centOS 7) it fails cause awk/gawk does not recognize the -i inplace input.

Example: example.txt

one 1
two 2
three   3

when trying:

awk -i inplace -F'\t' '{if ($1 == "two") print "four","4"; else print $0}' example.txt

output error:

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

I really need the awk script to work through inplace, I searched around and the web but found no clear solution, does anybody got a clue on how make it work?

Thanks a lot in advance for any help

cccnrc
  • 1,195
  • 11
  • 27

1 Answers1

1

As hek2mgl mentioned in case your awk is not having inplace option you could try like.

awk .....your code....Input_file > temp_file && mv temp_file Input_file
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93