END {
file = "a.txt"
system(cat file)
}
I wish to do something like that? (open a file whose name is in an awk variable). How is it done?
I wish to do something like that? (open a file whose name is in an awk variable). How is it done? |
||||
|
The problem is that system() passes the command line to a shell, so in the general case, you need to escape all shell special characters in the name of the file. awk has a ENVIRON associative array that is mapped to the environment it received, but unfortunately, assigning to it doesn't affect the environment of the commands executed via
Of course, if the file is "a.txt" or you can make sure that its path will never contain any shell special characters, you can get away with:
If you can make sure it doesn't contain single quote characters, you could do:
|
|||||
|
|
getline is your friend:
|
||||
|
|
|
If what you intend to do is to define the file that should be processed in the awk script itself, you could alter the ARGV array, and the ARGC variable accorgingly :
|
|||||||
|
cat-ing a file fromawk? Sounds like you are trying to do something uber-complex... – sparticvs Nov 12 '12 at 13:14catthe file. – learner Nov 12 '12 at 15:34