Luca Luca - 1 month ago 13
Linux Question

BASH exclude specific char from string

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

Answer

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