Iterating awk over a directory of files?

I need to run the same

awk 

function over an entire directly of files.
This is the

awk

:

awk '{$(NF+1)=1}1'

Is there a way that I can run this command once over all of the files, along the lines of:

awk '{$(NF+1)=1}1' *

so that I do not have to run this several times?
My main concern is how to output the results with a unique outfile name?

awk can write to whatever file you please.

awk 'L && (L != FILENAME) { close(L) }
{ L=FILENAME }
{$(NF+1)=1 ; print > L ".new" }' *

This will create "filename.new" for each "filename" fed into it. FILENAME is a special variable in awk which is set to what you'd expect.

If you want it to work recursively, you can use find.

1 Like

worked great! thanks !

1 Like