Need help with bash and strings
I'm trying to write a little script to weed out ip addresses from plain numbers, I've looked around but I'm kind of running into a brick wall. I was trying to go by the period between the numbers ex:
ip or number form matches 192.168.0.243 *.*.*.* yes 1937374087408 *.*.*.* no 8.3.100.5 *.*.*.* yes also trying to get a tab character in a string subsitution ie: echo ${x/]/tab tab tab hello} "\t" doesn't work, I need 8 tabs, any way I can do this? TIA |
ip or number form matches
Something like "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" ? I need 8 tabs, any way I can do this? Could use literal tabs: ctrl+v ctrl+tab ? |
Quote:
I thought C was the champion in terms of writing incomprehensible code. Note that, if you turn on extended REs, eg with egrep, you can shed some "\"s before the "{}"s. Also, can you not do something like: "([0-9]{1,3}.){3}[0-9]{1,3}"? (I have not tried this, so i am using it only to ask the question) |
This works:
Code:
sh-3.1$ ifconfig|egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' The -o options causes it to print only what it matches---in my case this: 137.79.94.73 137.79.94.255 255.255.255.0 127.0.0.1 255.0.0.0 |
Woop!
That worked, thanxs unspawn!
I just had to enable -e on echo to get the \t tabs to work.. thanks for your help pixellany! |
All times are GMT -5. The time now is 11:37 AM. |