How to create a file using awk

Hi there to the community,
i have a bash script with an awk command inside, the awk program is in a separate file cause it's a bit big.
Inside the awk program i calculate a filename from some data and i want to create a new file with this name into a directory whose path is passed in awk.

Etc. lets say that the awk command in the script looks like this :

awk -v target=$dir1/$dir2 -f inputfile

what i need to do is create (inside the awk program) a file called 'filename' under the target.
I 've been trying to do this with touch(), i know that system commands do not work in awk so i had to call touch() through system() to get it done.
So i am using

system ("touch "target/filename)

, but it doesn't work. Not that is generates an error, it simply does nothing.
If i write

system ("touch "filename)

the file is being created but the thing is that i want to create it in the directory pointed by target.
Any help? :slight_smile:

Maybe something like this ?

system ("touch "target"/filename")

tyler_durden

Hm this one creates a file under target but it's name is filename and not what the string variable filename is equal to. Any idea?

Seems like I misread your first post:

Anyway, try this -

system ("touch "target"/"filename)

which should create a file with the name that equals the value of the variable "filename", in the directory with the name that equals the value of the variable "target".

tyler_durden

Found another way by using :

path=sprintf("%s%s%s",target,"/",filename);
system("touch "path"");

A bit dummy but really made an effort!:smiley:
Yours works like a charm also, thanks a lot!