Run another awk from awk file

Is it possible to execute another awk file from an awk file? Using the awk file, I need to execute all awk files in the current folder. Is it possible to perform such operations in awk?

+4
source share
4 answers

Yes, you can. You need to use the system() function. I assume that you only want to run these scripts once. If so, you can add them to the BEGIN block of your wrapper script:

 BEGIN { system("awk -f ./script1.awk") system("awk -f ./script2.awk") system("awk -f ./script3.awk") } 

If you have a large number of scripts that need to be executed, you can use the for loop. Make sure your wrapper script is not in the same directory as all other awk scripts you want to execute, or they will be included in the glob of awk scripts ...

 BEGIN { system("for i in *.awk; do awk -f \"$i\"; done") } 
+6
source

1) Yes. 2) Do not do this.

awk is a word processing tool. The shell (or something that is passed to it on your OS) is a tool for invoking commands and managing files and processes.

Guess which one you should use to execute all awk commands on your file system?

If you tell us that your big problem, and your OS, we can help you.

+5
source

It is proposed to use the system function.

+2
source

General use of the system uses it to do something with the output file created only by awk script. It may not work if you do not close (output file) before calling the system.

0
source

Source: https://habr.com/ru/post/1447725/


All Articles