Suponha que tenhamos os seguintes arquivos de entrada
$ grep . */ps_results
RESULTS-172.16.10.1/ps_results:/usr/sbin/rsyslogd -n
RESULTS-172.16.10.2/ps_results:/sbin/rsyslogd -i /var/run/syslogd.pid -c 5
RESULTS-172.17.5.245/ps_results:/usr/sbin/rsyslogd -n -f /usr/syslog.conf
$
Então, quanto a
$ awk '/rsyslogd/{gsub("^.*RESULTS-","",FILENAME);gsub("/ps_results","",FILENAME);b="/etc/rsyslog.conf";for(a=0;a++<NF;){if($a=="-f"){b=$(a+1)}};printf "%-15s%s\n",FILENAME,b}' RESULTS*/ps_results
172.16.10.1 /etc/rsyslog.conf
172.16.10.2 /etc/rsyslog.conf
172.17.5.245 /usr/syslog.conf
$
O mesmo código, anotado + formatado:
awk '/rsyslogd/ {
# strip everything up to (and including) RESULTS- from the filename
gsub("^.*RESULTS-","",FILENAME)
# strip the /ps_results from the filename
gsub("/ps_results","",FILENAME)
# set the default rsyslog conf file
b="/etc/rsyslog.conf"
# look for a -f parameter: if found, grab conf file
for(a=0;a++<NF;){
if($a=="-f") {
b=$(a+1)
}
}
# print the ip addr and conf file
printf "%-15s%s\n",FILENAME,b
}' RESULTS*/ps_results