You could do something like this (but I wouldn't recommend it at all).
find dir -print0 |
xargs -0 -n 2 awk -v OFS='\0' '<process the input and write to temporary file>
END {print "temporaryfile", FILENAME}' |
xargs -0 -n 2 mv
This passes the files to awk
directly two at a time (which avoids the problem with your original where cat
will get hundreds (perhaps more) files as arguments all at once and spit all their content at awk
via standard input at once and thus lose their individual contents and filenames entirely).
It then has awk
write the processed output to a temporary file and then outputs the temporary filename and the original filename where xargs
picks them up (again two at a time) and runs mv
on the pairs of temporary file/original file names.
As I said at the beginning however this is a terrible way to do this.
If you have a new enough version of GNU awk
(version 4.1.0 or newer) then you could just use the -i
(in-place) argument to awk
and use (I believe):
find dir | xargs awk -i '......'
Without that I would use a while
loop of the form in Bash FAQ 001 to read the find
output line-by-line and operate on it in the loop.