Craig White wrote:
On Dec 6, 2012, at 1:59 PM, m.roth@5-cent.us wrote:
Craig White wrote:
On Dec 6, 2012, at 1:34 PM, m.roth@5-cent.us wrote:
You rang?
Craig White wrote:
<snip>
Definitely have little to no understanding of awk but…
Ok, I just d/l an nginx.conf file from http://wiki.nginx.org/FullExample and ran the following script on it: { if ( $1 ~ /server_name$/ ) { server = $2; gsub(/;|}/,"",server); print server; } }
and my o/p was $ awk -f nginx.awk nginx.conf domain1.com domain2.com big.server.com
not that I was looking for someone to write it for me but that works only
I do awk for *fun*.... <g>
when the nginx.conf looks like
server_name domain1.com domain2.com big.server.com;
which I actually didn't need to use awk to parse as I already handled those instances just fine with grep/sed
but I have some conf files which look like
server_name { domain1.com domain2.com big.server.com } ;
and that forced me into looking at alternative methods - hence awk
but your program gives me the following output…
<snip> Of course it didn't work. I've never worked with nginx, so I could only base it on what I found. With a file like that, I'd write { if ( found == 1 && NF == 1 ) { if ( $1 ~ /}/ ) { found = 0; } else { print $1; } } else { if ( $1 ~ /server_name$/ && $2 ~ /{/ ) { found = 1; } } }
mark