Let's say I have file.txt
water 1
lorem 0
ipsum 0
I cut the last column and redirect output to file itself with this:
cut -d' ' -f 1 file.txt > file.txt
I expect current content of file.txt
is
water
lorem
ipsum
However, I got blank file in file.txt
>
. – Stephen Kitt Feb 11 '22 at 07:31cut -d' ' -f1 file.txt> temp && mv temp file.txt
– Muhammad Ikhwan Perwira Feb 11 '22 at 07:44awk -i inplace '{print $1}' file.txt
– pLumo Feb 11 '22 at 08:02cut -d' ' -f 1 file.txt | sponge file.txt
.sponge
collects all the output, then writes it to the named file (no redirection) after the previous program has finished reading it. – Paul_Pedant Feb 11 '22 at 08:10