Re: Bash Script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 10:45 +0600 11/21/2005, Kev wrote:
im having a prb transferring the ip in reveres format (192.168.1.2 --> 2.1.168.192)

can any one help me to do this with a bash script ?

Pure BASH:

ip=10.1.22.123 # test address

rev="${ip##*.}" # Get last octet
tmp="${ip%.*}" # Strip last octet
rev="${rev}.${tmp##*.}" # Add third octet
tmp="${tmp%.*}" # Strip third octet
rev="${rev}.${tmp#*.}.${tmp%.*}" # Add first two octets (in reverse order)
unset tmp

echo "$rev" # Display reversed address

--
Jeff Woods <kazrak+kernel@xxxxxxxxxxx>
-
: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Newbie]     [Audio]     [Hams]     [Kernel Newbies]     [Util Linux NG]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Device Drivers]     [Samba]     [Video 4 Linux]     [Git]     [Fedora Users]

  Powered by Linux