Got a bunch of files with domain qualified names in them, looking to replace them by their ip.Can I do that with one line of shell ( bash ) ?Typical input file ( nagiosconf ) : define host {        host_name                       host1        use                             model        alias                           myalias        address                         myhost.domain}define service {        host_name                       hostname        use                             Modele_Ping}The idea is to replace myhost.domain by its ip ( as returned by nslookup or other tools ).I can always script it, but I was wondering if there was a unix smart way to do it.
Sed dynamic substitute, the unix way?
shell;sed
This may need some tweaking, but:<source_file while read -r line; do    part=$(echo $line | egrep -o '\w+\.\w+')    if [[ $? == 0 ]]; then        addr=$(dig $part +short | head -n1)        echo ${line/$part/$addr}    else        echo $line    fidoneThis will look up any domains of the form part1.part2. Mess with the regex to change what exactly it tries to look up. It will only look up one address per line.