I am learning awk
and I would like to know if there is an option to write changes to file, similar to sed
where I would use -i
option
following won't work
echo $(awk '{awk code}' file) > file
this should work
echo "$(awk '{awk code}' file)" > file
An alternative is to use sponge
:
awk '{print $0}' your_file | sponge your_file
Where you replace '{print $0}'
by your awk script and your_file
by the name of the file you want to edit in place.
sponge
absorbs entirely the input before saving it to the file.