ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Good Folks,
I have a gawk script that parses a file created in the BEGIN section.
The script works perfectly, but I have to include the dynamically created file on the command line.
An example begin section:
Code:
BEGIN {
system("ls -1 > /tmp/foo.tmp")
}
If the script name is foo.awk, the command line must be:
Quote:
foo.awk /tmp/foo.tmp
I know I can write a shell script that fires off the above command line, but is there a way to somehow specify the input file within the gawk script itself?
Location: Fleury-les-Aubrais, 120 km south of Paris
Distribution: Devuan, Debian, Mandrake, Freeduc (the one I used to work on), Slackware, MacOS X
Posts: 251
Rep:
I don't understand what you want to do exactly. The obvious for me would be to get the $1 coming from the command line, but since you're asking I guess I probably miss the whole problem...
Hi.
First of all, I agree with all opinions above and suggest you to consider them carefully.
But, it is indeed possible to specify a file to process from the awk script itself. Here's an example:
Code:
$ awk 'BEGIN{ARGV[1]="/proc/cpuinfo"; ARGC=2} {print}'
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i7-3517U CPU @ 1.90GHz
stepping : 9
microcode : 0x15
cpu MHz : 1291.218
cache size : 4096 KB
physical id : 0
siblings : 4
core id : 0
.....
And, of course, one can also read a file manually using getline.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.