awk : dynamic output flatfile filename

Hello,

I'm using the awk command to insert empty columns on a tab delimited flatfile - which works fine -
=> But I'm not able to manage dynamicaly the filename of the awk output based on the source flatfile filename

I have 3 source flatfile:

flatfile_Jan-2016.csv
flatfile_Feb-2016.csv
flatfile_Mar-2016.csv

And I would like to output the result of the awk command to

newflatfile_Jan-2016.csv
newflatfile_Feb-2016.csv
newflatfile_Mar-2016.csv

Below the awk command which is working for inserting empty columns but I'm not able to manage dynamically the target flatfile filename

awk -F"\t" '$6="\t" $6' OFS="\t" *flatfile* > flatfile_Jan-2016.dat

Thanks!

Try (untested):

awk -F"\t" '{$6="\t" $6; print > ("new" FILENAME)' OFS="\t" *flatfile*

Note that to avoid processing newflatfile_Mon-YEAR.csv files if you run this script multiple times, you probably want to just use flatfile* instead of *flatfile* as the filename matching pattern in your script.

thank you all, it is working like a charm!