a little out of my comfort zone and have practically gotten what I want but awk
seems determined to send a message via std error which is problematic and
annoying. Basically trying to get a list of virtual host names from nginx config
files like this:
$ awk -F" " '/./ { if ( match ( "^server_name$", $2 ) )
print $1 }' /opt/nginx/sites/*.conf \
| grep -v server_name | grep -v ';' | grep -v '}'
and the list of virtual host names is perfect except that I get this line
first...
awk: (FILENAME=/opt/nginx/sites/ids.conf FNR=55) fatal: Unmatched ( or \(:
/($host/
and I can't seem to dismiss it and I definitely don't want it in my data
scrape.
Anyone know how to prevent this? (yes, there are lines in the file that say
'if ($host = something) {'
--
Craig White ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ craig.white at ttiltd.com
1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ www.ttiassessments.com
Register Now!
TTI Winners' Conference 2013
January 20th - 22nd
The Earlier You Register the More FREE Product You Receive
Click here for more information!
On Thu, Dec 6, 2012 at 2:07 PM, Craig White <craig.white at ttiltd.com> wrote:> a little out of my comfort zone and have practically gotten what I want but awk seems determined to send a message via std error which is problematic and annoying. Basically trying to get a list of virtual host names from nginx config files like this: > > $ awk -F" " '/./ { if ( match ( "^server_name$", $2 ) ) print $1 }' /opt/nginx/sites/*.conf \ > | grep -v server_name | grep -v ';' | grep -v '}' > > and the list of virtual host names is perfect except that I get this line first... > > awk: (FILENAME=/opt/nginx/sites/ids.conf FNR=55) fatal: Unmatched ( or \(: /($host/ > > and I can't seem to dismiss it and I definitely don't want it in my data scrape. > > Anyone know how to prevent this? (yes, there are lines in the file that say 'if ($host = something) {'I'd start with perl instead of awk and come up with something that didn't need the greps to clean it up. But, if all you want is to discard stderr, won't sticking a 2>/dev/null before your first pipe take care of that courtesy of shell redirection? -- Les Mikesell lesmikesell at gmail.com
You rang? Craig White wrote:> a little out of my comfort zone and have practically gotten what I want > but awk seems determined to send a message via std error which is > problematic and annoying. Basically trying to get a list of virtual host > names from nginx config files like this: > > $ awk -F" " '/./ { if ( match ( "^server_name$", $2 ) ) print $1 }' > /opt/nginx/sites/*.conf \ > | grep -v server_name | grep -v ';' | grep -v '}'Why are you doing all that piping and grepping? And the -F" " confuses me...oh, I see. First, whitespace is the default field separator in awk. Then, are you asking if there's a line with a "." in it, or just any non-whitespace? If the latter... mmm, I see, you *really* don't understand awk. awk -f '{if ( $1 ~ /server_name/ ) {\ server = $2;\ gsub(/;|}/,"",server);\ print server; } }' <snip> mark