How to use awk to display file like cat command

I know cat filename will show contains of the file. How can I imitate such model within awk? What I need is display file contains in BEGIN { .. } awk block. Is that possible? How do we cat a file from awk and display it on screen?

Try using awk’s system():

awk 'BEING {  system("cat /path/to/filename") } { ... } END { ...}' input

Another option is as follows to cat file using awk:

awk 'BEGIN {while ((getline<"/path/to/filename") > 0) {print}}'
1 Like

I made a little change. :smile:

awk 'BEING {template="temp.html";  system("cat " template) } { ... } END { ...}' input

You can check man awk :wink: For simple print in the console: awk '{print}' /path/bla/bla/text.tx
or you can check here: Linux_Deployment_Administration_Hacks-Programing/AWK at master · nu11secur1ty/Linux_Deployment_Administration_Hacks-Programing · GitHub :wink:
BR =)