On 4/30/23, cor...@free.fr <cor...@free.fr> wrote: > Hello list, > > I wrote this script for reversing an IP: > > #!/bin/bash > > IP=$1 > > if [ -z $IP ];then > echo "$0 IP" > exit 1 > fi > > REVERSE=$(echo $IP|awk -F\. '{print $4.$3.$2.$1}') > echo $REVERSE > > > it won't work as the output below. > > $ bin/rbl.sh 61.144.56.32 > 325614461 > > > The "." was lost. > > If I changed the awk line to: > REVERSE=$(echo $IP|awk -F\. '{print "$4.$3.$2.$1"}') > > > It becomes: > > $ bin/rbl.sh 61.144.56.32 > $4.$3.$2.$1 > > > > Can you help with this?
$ cat /tmp/reverse #!/bin/bash IP=$1 if [ -z $IP ];then echo "$0 IP" exit 1 fi REVERSE=$(echo $IP|awk -F\. '{printf("%s.%s.%s.%s\n", $4, $3, $2, $1) }') echo $REVERSE $ /tmp/reverse 61.144.56.32 32.56.144.61 Regards Lee