This seems to work for me:
# ifconfig eth0 | grep "inet addr:" | cut -d ":" -f 2 | cut -d " " -f1
192.168.1.100
Basically, it uses the output of "ifconfig eth0" and pipes it through grep and cut to get to the field in the output that displays the ip.
Here's my output for ifconfig eth0:
# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:50:BA:CC:A7:A2
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:205433 errors:0 dropped:0 overruns:0 frame:0
TX packets:186536 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:226189854 (215.7 Mb) TX bytes:27294230 (26.0 Mb)
Interrupt:21 Base address:0x6c00
If your format is similar, the above command should work. But if your on a lan, you'll only get your local ip in the network as I did above. In that case, you can get your ip with:
$ curl -s
http://www.whatismyip.com/ | grep '<TITLE>' | cut -d " " -f 4
which outputs the text between the third and fourth spaces which is your ip.