Acho que isso acontece, se awk
estiver ok.
#! /usr/bin/awk -f
# here, NR is record number, and FNR is *file* record number - this matches only
# in first file
NR == FNR {
# if first field matches
if ($1 ~ /abc/) {
# arrange addresses with '", "' between them
abc=$2
for (i=3; i<=NF; i++) abc = abc "\", \"" $i
}
# then we're finished with this file.
next;
}
$1 ~ /hosts/ {
# print the saved addresses formatted with '["' addr '"]'
printf " %s [\"%s\"]\n", $1, abc ;
next
}
# print any other lines with no editing.
{ print }
Fornece saída para o arquivo atualizado como abaixo. Observe que a variável interna RS (record seperator) está sendo atualizada entre os arquivos, para tratar cada um separadamente.
~$ ./log_edit RS='[' hosts RS='\n' logstash
output.logstash:
# The Logstash hosts
hosts: ["192.168.29.153", "192.168.29.155"]
# Optional SSL. By default is off.
# List of root certificates for HTTPS server verifications
#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
# Certificate for SSL client authentication
#ssl.certificate: "/etc/pki/client/cert.pem
Você também precisará salvar a saída e substituir o arquivo antigo.