Reputation: 41
I must implement one script, i should get list of virtual hosts apache:
apachectl -S | grep -i site | awk '{print $5}'
output:
Syntax OK
(/usr/local/apache2/conf/site.conf:1)
how can i receive this output? (without Syntax OK/()/:*):
/usr/local/apache2/conf/site.conf
Upvotes: 0
Views: 548
Reputation: 204239
The Syntax OK text must be going to stderr, it's not going to stdout or it'd get filtered out by the grep/awk. Try this:
apachectl -S 2>&1 | awk '$5~/site/{gsub(/^\(|:[^:]+\)$/,"",$5); print $5}'
Upvotes: 1
Reputation: 1139
Using a regular expression to capture from the opening parenthesis to the ":"
apachectl -S 2>&1 | perl -ne '/\((.*site.*):/i && {print $1}'
Upvotes: 0
Reputation: 42107
With awk
setting (
, )
and :
as field separators, and getting the second field:
awk -F'[():]' '{print $2}'
Example:
% awk -F'[():]' '{print $2}' <<<'Syntax OK (/usr/local/apache2/conf/site.conf:1)'
/usr/local/apache2/conf/site.conf
Upvotes: 1