On Wed, May 18, 2016 at 10:25:02PM +0100, aide...@gentoo.org wrote:
> From: Amadeusz Żołnowski <aide...@gentoo.org>
> 
> awk doesn't have the -i option like sed and if editing file in place is
> desired, additional steps are required. eawk uses tmp file to make it
> look to the caller editing happens in place.
NAK.

1.
If your AWK command has an error, then this clobbers the file, a better
variant, with die, would be:
awk "$@" "$f" >"${tmpf}" || die "awk failed..."
cp -f "${tmpf}" "$f" || die "copy back failed"

> # @USAGE: <file> <args>
This calling format is also a problem if they intended to pass multiple
files to the command, or if they do so accidentally. 

Eg, an unprotected glob in the first argument, eg:
eawk foo* '/foobar/{$1="x"; print $0}'

If foo1 and foo2 existed, this would be considered as:
awk foo2 /foobar/{$1="x"; print $0}' foo1

which really will NOT have the desired effect.

-- 
Robin Hugh Johnson
Gentoo Linux: Dev, Infra Lead, Foundation Trustee & Treasurer
E-Mail   : robb...@gentoo.org
GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
GnuPG FP : 7D0B3CEB E9B85B1F 825BCECF EE05E6F6 A48F6136

Reply via email to