how to grep ip address ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to grep ip address ?
# 1  
Old 11-05-2009
how to grep ip address ?

hi,

Pls advice me, how to grep only the ip address from the following output:

<ip>10.4.65.67</ip>
<TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>false</TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>
<TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>false</TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>
<ip>10.4.65.67</ip>
<TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>false</TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>
<TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>false</TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>
<ip>10.4.65.172</ip>
<TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>false</TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>
<TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>false</TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>
<ip>10.4.65.46</ip>
<TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>false</TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>
<TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>false</TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>
<ip>10.4.65.46</ip>
<ip>10.4.65.237</ip>
<TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>false</TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>
<TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>false</TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>
<ip>10.4.65.79</ip>
<TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>false</TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA>
<TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>false</TLS_RSA_EXPORT1024_WITH_RC4_56_SHA>
<ip>10.4.65.79</ip>



for example:
I want the output as:
10.4.65.67
10.4.65.67
10.4.65.172
10.4.65.46
10.4.65.46
10.4.65.237
10.4.65.79
10.4.65.79
# 2  
Old 11-05-2009
Code:
sed -n "s+<ip>\(.*\)<.*+\1+p" file1 
10.4.65.67
10.4.65.67
10.4.65.172
10.4.65.46
10.4.65.46
10.4.65.237
10.4.65.79
10.4.65.79

Or if your awk support this:
Code:
awk -F"[<>]" '/ip/ { print $3 }' file1 
10.4.65.67
10.4.65.67
10.4.65.172
10.4.65.46
10.4.65.46
10.4.65.237
10.4.65.79
10.4.65.79

or
awk -F"</*ip>" '/ip/ { print $2 }' file1

# 3  
Old 11-05-2009
try...

Code:
cat file | grep "<ip>" | awk -F "[<ip></ip>]" '{print $5}'

The solution of scottn is better....i have to learn a lot....
# 4  
Old 11-05-2009
Hi
Try this

grep "ip" <filename>|cut -f2 -d"<"|cut -f2 -d">"

Regards,
Pankaj

---------- Post updated at 07:27 AM ---------- Previous update was at 07:17 AM ----------

Hi Scottn,

May i request you to explain the command u have send

awk -F"[<>]" '/ip/ { print $3 }' filename - why "/ip/" need to mentione over here?

sed -n "s+<ip>\(.*\)<.*+\1+p" filename - i could not understand... Smilie

Regards,
Pankaj
# 5  
Old 11-05-2009
grep -e '^[1-9][0-9]\.[1-9][0-9]\.[1-9][0-9][]0-9]\.[1-9][0-9][]0-9]' file
# 6  
Old 11-05-2009
Quote:
Originally Posted by panknil
May i request you to explain the command u have send

awk -F"[<>]" '/ip/ { print $3 }' filename - why "/ip/" need to mentione over here?
If awk supports it you can specify more than one field separator (-F"[<>]") or field separators with more that one character or with regular expressions ("</*ip>"). And I only want lines with ip in them (/ip/)

Better maybe would have been
Code:
$2 == "ip" { print $3 }

Quote:
Originally Posted by panknil
sed -n "s+<ip>\(.*\)<.*+\1+p" filename - i could not understand... Smilie
remember everything after "<ip>" ( \(.*\) ) and before the next (actually the last) "<", and then print it "...\1p"
I don't know what "better is" here, because my regex's are rubbish!

Quote:
Originally Posted by dddkiran
grep -e '^[1-9][0-9]\.[1-9][0-9]\.[1-9][0-9][]0-9]\.[1-9][0-9][]0-9]' file
OK if you want the whole line with the IP address in it. And I can't see a dot (.) on any other line, so based on the input file
Code:
grep \\. file

would have done the same thing.
# 7  
Old 11-05-2009
Code:
awk '/ip/{gsub(/<ip>|<\/ip>/,"");print}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep for ip address only from a file

Facing issues in grepping only the IP Address from a file i have tried the below and it was of not much help awk -F"" '/(/ { print $3 }' awk -F"</*(>" '/ip/ { print $2 }' grep "ip" file1|cut -f2 -d"<"|cut -f2 -d">" grep "(" file1 |cut -f2 -d"<"|cut -f2 -d">" grep -e... (9 Replies)
Discussion started by: satishcarya
9 Replies

2. Shell Programming and Scripting

GREP mac address

Hi, mac.txt My mac address is <Mac Address>. How can i replace <Mac Address> with the actual of my computer? I try to GREP command as below but i am unable to grep it to replace just <Mac Address>. ifconfig eth0 | grep -o -E '(]{1,2}:){5}]{1,2}' Million in Advance. Please use... (7 Replies)
Discussion started by: derrickyee81
7 Replies

3. UNIX for Dummies Questions & Answers

Grep exact IP address from file

I have a file with a lot of IP addresses in it named "address.list". address.list looks something like this: 10.77.50.11 10.77.50.110 10.77.50.111 a bunch more addresses For every IP address I need to grep another file to see if the IP address is in the other file: for x in `cat... (5 Replies)
Discussion started by: squoggle
5 Replies

4. Shell Programming and Scripting

grep ip address from file

I have a file $ cat ip12 11.22.33.44 192.68.1.2 helo l 72.34.34.200 333.444.555.666 12.23e.544.423 myip1 11.22.33.44 myip2 33.44.55.66 #fine this IP should also be listed I do $ cat ip12 | grep '^\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}$' 11.22.33.44 192.68.1.2 (2 Replies)
Discussion started by: anil510
2 Replies

5. UNIX for Dummies Questions & Answers

grep or sed help for a word and an IP address

I would like to grab only designates and the IP address next to it. I can also live with client-ip=xx.xx.xx.xx Any help is much appreciated. line to grep or sed: Received-SPF: pass (google.com: domain of support@uhb-hosting.de designates 80.67.28.12 as permitted sender)... (7 Replies)
Discussion started by: tigta09
7 Replies

6. Shell Programming and Scripting

grep ip address

I need to find out whether a line in a text file contains an ip address or a hostname. How can I do this? For example: 123.2.34.55 host1 host2.domain.com host3.intra.domain.com Then I want as result a list with ip addresses and hostnames. (2 Replies)
Discussion started by: rein
2 Replies

7. UNIX for Dummies Questions & Answers

Grep Ip address

I'm looking a Grep or egrep statement that would allow me to exclude the a range of ip address via the last octet example egrep -v "*.*.*.(54|61)" from a syslog file.... would this work? (6 Replies)
Discussion started by: wfleenor
6 Replies

8. Shell Programming and Scripting

how to grep only IP address of e1000g0 using ifconfig -a

Hello All, Can someone show me how to cat "only the IP address of e1000g0" using ifconfig -a. i am trying to grep only the ip address (xx.xx.xx.xx) from the bunch of all other things like, broadcast address, IPV4, UP........and so on. thanks (1 Reply)
Discussion started by: solaix14
1 Replies

9. Shell Programming and Scripting

how grep the inet address for in ifconfig command

hi, i want to know how to grep inet address for below below is the output of ifconfig command /home/JA> ifconfig eth0 Link encap:Ethernet HWaddr 00:11:0A:5B:2E:E9 inet addr:161.239.203.18 Bcast:161.239.203.127 Mask:255.255.255.128 UP BROADCAST RUNNING... (3 Replies)
Discussion started by: mail2sant
3 Replies

10. Shell Programming and Scripting

How to grep dhcp ip address

Hi, I have a script that my operators use as a login profile. As they need to export their display in order to access the GUI of the data protector program in HPUX machine. Anyone can advise how I can grep (eg. who -r) the dynamically assigned IP address and automatically put it as a variable... (4 Replies)
Discussion started by: chongkls77
4 Replies
Login or Register to Ask a Question