You're script is doing too much. The cleanest solution, to my mind, inverts the condition:
awk '{ if ($2 > 25) print }'
or even:
awk '$2 > 25'
If you don't want to invert the condition, then:
awk '{ if ($2 <= 25) next; print }'
There's no need to iterate over all the fields.
Not even GNU awk
supports 'in situ' file modification. You have to write the result to a temporary file, and then copy or move the temporary back over the original. (Copy preserves hard links and permissions; move breaks links and can modify owner and permissions. You need to decide whether that's a concern.)
Thanks to Ed Morton for pointing out that GNU Awk 4.x does have a mechanism to edit files 'in situ', in part because he campaigned to get it added.
The command line help won't tell you that GNU Awk 4.x supports in-place modification of files, but if you find the right part of the manual (Extension sample: inplace — which is mis-titled from my perspective; it isn't just a sample because it is a distributed extension) then you can find out that there is an extension that makes GNU Awk overwrite regular files specified on its command line.
gawk -i inplace '{ if ($2 > 25) print }' file1 …
or even:
gawk -i inplace '$2 > 25' file1 …
Note that experimentation shows that it is quite happy to modify read-only files in situ. This is consistent with sed
(both GNU and BSD (Mac OS X) sub-species); they also modify read-only files in situ without warning — and preserve the permissions on the file but break any hard links.
Your script uses awk '…' < *
; that is a peculiar way of ignoring the first file in your directory unless it is the only file in the directory (it is used for standard input, but if there's more than one file in the directory, standard input is ignored). You need to use just *
, not < *
.