Hi everybody,
I am working on a bigger awk script in which one part is comparing the size of two files.
I want to evaluate which file is bigger and then just save the bigger one.
I got it all working except for the part where I want to figure out which file is bigger; the one awk is currently reading (->FILENAME) or the one that already lies there.
So how do you get the output of
stat -c %s
into awk while supplying it with FILENAME?
I tried it with getline:
awk '{\
if (FNR ==1) {\
"stat -c %s "FILENAME |getline fsize\
if (fsize <= ....){\
...}\
}\
}' /export/hundreds/of/files/*
But that ends up in <Permission Denied> (Don't ask me why, I am the owner of the script as well as the files to be read)
Another approach was system():
awk '{\
if (FNR == 1) {\
fsize = system("stat -c %s " FILENAME)\
if (fsize <= ....){\
...}\
}\
}' /export/hundreds/of/files/*
But fsize ends up being 0, since its just the status of the cmd, or something like that.
Next approach I found online involved something like this:
x="'"`stat -c %s FILENAME`"'"
But that obviously can't work because FILENAME is an awk variable. And I don't see a way of putting FILENAME in that command.
It would be really great if someone has some idea on how to solve the problem. I have been sitting on this problem for a couple of hours now and I am starting to go nuts...