There are two main ways to go about this.
Use a shell loop in which you call your awk
code and redirect the output to a name that is derived from the current input file, or
Call awk
once with all files as arguments, and do the output to an appropriately named file inside your awk
script. Note that this would only be possible if you have fewer than thousands of files.
I will not touch upon the second of these two as we can't see your awk
code and therefore can't suggest what needs to be changed in it (if you're using NR
, for example, this may possibly have to change to using FNR
, and there may be other changes needed too).
Using a shell loop:
for pathname in /FILES/detail-*:??; do
name=${pathname##*/}
awk -f script.awk "$pathname" >"${name%:??}_${name##*:}.csv"
done
The three parameter substitutions used here:
${pathname##*/}
, removes the directory path from the pathname and leaves just the filename portion of the string.
${name%:??}
, removes the trailing :
character and the two characters after that from the filename in name
. This bit is then concatenated with an underscore and with ...
${name##*:}.csv
, removes everything up to the :
at the end of the filename and adds a .csv
filename suffix at the end.
The 2nd and 3rd substitutions are used to replace the :
at the end of the filename with _
to create the output filename.