Grep IP address form a text file along with the subnet


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep IP address form a text file along with the subnet
# 1  
Old 04-09-2013
Grep IP address form a text file along with the subnet

I have an input file:

Code:
class 1 3 5 10.10.10..0/23 hicks jimmy
class 3 10.12.10.0/22 mike
class.019283 10.10.15.10/20 henry
gym.847585 45 192.168.10.0/22 nancy jim steve maya

The output should look like this:

Code:
10.10.10..0/23
10.12.10.0/22
10.10.15.10/20
192.168.10.0/22

I have the following but it only prints the ip address
Code:
perl -lne 'print $& if /(\d+\.){3}\d+/'  file

Regards,
# 2  
Old 04-09-2013
Code:
egrep -o '[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+/[0-9]+' inputfile

# 3  
Old 04-09-2013
I see two periods . in your first line, not sure if that is valid:
Code:
10.10.10..0/23
10.12.10.0/22
10.10.15.10/20
192.168.10.0/22

But if that is valid and if you really want that in output:
Code:
awk '{match($0, /[0-9]+\.[0-9]+\.[0-9]+\.*[0-9]+\/[0-9]+/); print substr($0, RSTART, RLENGTH)}' file

Use /usr/xpg4/bin/awk or nawk in Solaris.
# 4  
Old 04-09-2013
The code does work in Solaris. -o option

---------- Post updated at 11:41 AM ---------- Previous update was at 11:32 AM ----------

The second period is a typo. sorry

---------- Post updated at 11:42 AM ---------- Previous update was at 11:41 AM ----------

Thank you. it works
This User Gave Thanks to e_mikey_2000 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I need to appears as different ip address when I send a form

Hi my problem is that I need to send a form to a web address using curl, from a unix shell, the web address on the receiving end will only accept incoming data from a specific ip address, and port, on another machine on our intranet, and I can not run curl on that machine. Is there any way I... (5 Replies)
Discussion started by: Paul Walker
5 Replies

2. Shell Programming and Scripting

Get all ip address from subnet mask

I have this subnet file shown below. How can I calculate all ip addresses from that list 103.22.200.0/22 141.101.64.0/18 10.0.0.0/22I need to be able to read the subnet file and print all IPs in those subnet to an out put file (3 Replies)
Discussion started by: e_mikey_2000
3 Replies

3. Windows & DOS: Issues & Discussions

Removing characters form text file and replaicng

I currently have a text file which looks like this 2010.26 (0.0306746) @ 59,19 I want to remove all 22 characters up till the "59" NOTE: REMOVE, not replace with (null) NOTE2: The 59 CANNOT be taken as a number to consider in the script... it is not fixed. The only thing that is fixed is... (2 Replies)
Discussion started by: pasc
2 Replies

4. IP Networking

lookup ip address, subnet mask, gateway, and dns at same time

Is there a command that can lookup ip address, subnet mask, gateway, and dns all at the same. I know ifconfig can lookup ip address and subnet mask. I know route -n can lookup gateway. Not sure about a dns command. So I hope there is a way to lookup ip address, subnet mask, gateway, and dns all at... (2 Replies)
Discussion started by: cokedude
2 Replies

5. UNIX for Dummies Questions & Answers

Text file + image/form/overlay file to PDF

Hi, We have an app specific legacy environment running SCO Openserver 5.0.7. I need to be able to (1) scan a pre-existing “form” consisting of logo/boxes/lines/static text as an image , (2) lay a print file from the app "on top of the image" and (3) output the "merge" as a PDF file. Scanning... (1 Reply)
Discussion started by: 65bit
1 Replies

6. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

7. Shell Programming and Scripting

how to grep the max length word form a file?

Hi i have a requirement that is extract the max length word from a file ? plz reply (2 Replies)
Discussion started by: vankireddy
2 Replies

8. Shell Programming and Scripting

ip address and subnet comparing

Hmmm, tough question for me, so I put it here. I am trying to use shell script or mysql to do the following thing. tableA, in which all are single ips. sip ------- 1.2.3.4 8.8.8.8 123.3.32.1 .... and tableB, a list of our group subnets. subnet --------- 1.0.0.0/8 20.0.1.0/24 (2 Replies)
Discussion started by: fedora
2 Replies

9. SCO

ACL for Subnet/IP address

I am trying to find out if you can create an ACL for telnet sessions and restrict it to a certain subnet/IP range.. any information or where to look would be greatly appreciated. thanks (1 Reply)
Discussion started by: marvin51796
1 Replies

10. UNIX for Dummies Questions & Answers

Modifying IP Address/Gateway/Subnet in SCO Unix

Hi, I'm new to unix and have absolutely no experience with it. I am trying to change the network setting on the only computer on our network with SCO Unix. We switched ISP's and now have a new set of IP's. I can't for the life of me figure out how to go in and change these settings, please help.... (12 Replies)
Discussion started by: PBNOSGT
12 Replies
Login or Register to Ask a Question