In this comment, community member DannyDannyDanny asked if it is safe to redirect output of the awk
command to the same file being used for input.
No one answered that comment, so I would like to formally ask that question here.
Specifically, my intent is to use this awk
command:
awk '!($0 in a) {if (NF) a[$0]; print}' filename > filename
Please note that filename
= filename
.
sponge
, a tool fromGNU
more-utils
:awk ... file | sponge file
– Gilles Quénot Feb 28 '24 at 00:06inplace
, see https://unix.stackexchange.com/a/749646/70524 on how to use it safely – muru Feb 28 '24 at 00:08awk 'NF && !seen[$0]++' filename
. – Ed Morton Feb 28 '24 at 12:17