I am going through a tutorial on awk which requires using '.awk' file. I am having issues going forward with it as awk is not working as expected. Here is the code I am using. Contents of the virt.awk file
BEGIN { RS="\n\n" ; }
$0 ~ search { print }
Now the expected result is I search for a pattern and the particular Record should be displayed. But when I try the following I get the entire file displayed.
Command I am using:
awk -f virt.awk search=domain1 virtualhosts.conf
No matter what I use in the search term, I get the entire file printed. All entries of domain1, domain2 domain3 etc Could someone please help?
Note: it is just a copy of virtualhosts.conf file and it is preformatted to have exactly the format i.e. blank line after each entry and no additional blank lines in between.
Contents of virtualhost.conf: (and the result I am getting always):
<VirtualHost 172.20.30.40:80>
DocumentRoot "/www/domain1"
ServerName www.domain1.com
#Other options
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
DocumentRoot "/www/domain2"
ServerName www.domain2.com
#Other options
</VirtualHost>
<VirtualHost 172.20.30.50:80>
DocumentRoot "/www/domain3-80"
ServerName www.domian3.org
#Other options
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
DocumentRoot "/www/example2-8080"
ServerName www.example.org
#Other options
</VirtualHost>
Additional Details: I found that I was using mawk so I installed gawk but I still get the same result. I am using pop-os 20.04 and dash by the way (if that affects anything)
user@pop-os:~/linuxwork$ which awk
/usr/bin/awk
user@pop-os:~/linuxwork$ ll /usr/bin/awk
lrwxrwxrwx 1 root root 21 Mar 30 21:10 /usr/bin/awk -> /etc/alternatives/awk*
user@pop-os:~/linuxwork$ ll /etc/alternatives/awk
lrwxrwxrwx 1 root root 13 Aug 6 20:21 /etc/alternatives/awk -> /usr/bin/gawk*
user@pop-os:~/linuxwork$