Reversing The Order of the IP Address with Sed

by bitznbitez

There exist absolutely no practical application for the following bit of sed.   Well no positive application anyway.   I suppose one could use it for the forces of evil.   Its point is to demonstrate matching of IP addresses in a file.

sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1/'

Its used as follows :

 %grep localhost /etc/hosts
127.0.0.1       loopback        localhost
%grep localhost /etc/hosts | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1/'
1.0.0.127       loopback        localhost
Advertisements