Reformatting IP address
Hi guys, me again,
I'll make this short Whos magic with regex's and sed? I am getting heading 0's from the ip routing table on my router, eg 0xx.00x.xxx.00x I'm imagining something with sed wud be perfect but i cant get the right expression to match I'm thinking s/\.0*/./ but it isnt working. Ideas? Cheers |
Quote:
|
get rid of the 0's as they are not recognised by any other tools, eg.
if an ipaddress being accessed is 10.1.1.1, i would read from this source 010.001.001.001, and i want to turn that back into 10.1.1.1 make more sense now? I want to remove any zeros that immediatly follow a decimal or are at the very beginning of the line. |
sed -e 's/[0]*\([0-9]*\)\.[0]*\([0-9]*\)\.[0]*\([0-9]*\)\.[0]*\([0-9]*\)/\1.\2.\3.\4/g' <text_file_with_ip_addys> | sed -e 's/\.\./\.0\./'
Ugly as sin, but it works...heh This would be insanely easy with a Python script, by the way... |
I could live with python...
Go on.... |
Code:
#!/usr/bin/env python |
Simple, Elegant, I like it *steals*
Thanks for all the help guys :D |
This uses GNU sed to delete one or two 0's after a word boundary:-
Code:
echo 011.100.000.001 | sed 's/\b00\?//g' |
Quote:
|
All times are GMT -5. The time now is 07:11 AM. |