I am doing some text process on a file using awk. For instance removing the trailing whitespace.
awk '{gsub(/ +$/, "")} {print $0}' filename
This works fine. But when I redirect the output to the original file. It becomes an empty file.
temp$ awk '{gsub(/ +$/, "")} {print $0}' abc > abc
temp$ cat abc
temp$
So I tried another way. Use cat and pipe rather than as a input parameter of awk.
temp$ cat abc | awk '{gsub(/ +$/, "")} {print $0}' abc > abc
temp$ cat abc
temp$
Still doesn't work. Is there a way to achieve the same goal without involving an intermediate file?