egrep getting numbers only


 
Thread Tools Search this Thread
# 1  
egrep getting numbers only

Hello, I am kind of a noob with unix, so i'd like some help.

I am trying to get some ip address with an nmap scan and then put from the result of the scan only the ip numbers

this is an example

Code:
Starting Nmap 5.21 ( Nmap - Free Security Scanner For Network Exploration & Security Audits ) at 2012-05-25 12:29 CEST
Nmap scan report for 114.86.196.165
Host is up (0.50s latency).
PORT   STATE SERVICE
80/tcp open  http

Nmap scan report for twdp-066-026-105-245.nc.res.rr.com (66.26.105.245)
Host is up (0.17s latency).
PORT   STATE SERVICE
80/tcp open  http

Nmap scan report for ns2.km20718.keymachine.de (84.19.181.228)
Host is up (0.071s latency).
PORT   STATE SERVICE
80/tcp open  http

Nmap scan report for 211.143.184.144
Host is up (0.38s latency).
PORT   STATE SERVICE
80/tcp open  http

Nmap scan report for hosted.by.pacificrack.com (66.154.109.107)
Host is up (0.41s latency).
PORT   STATE SERVICE
80/tcp open  http

Nmap scan report for 87-198-189-161.static.ptr.magnet.ie (87.198.189.161)
Host is up (0.12s latency).
PORT   STATE  SERVICE
80/tcp closed http

Nmap scan report for hh-wedc-75-201.lut.ac.uk (158.125.75.201)
Host is up (0.11s latency).
PORT   STATE  SERVICE
80/tcp closed http


what i would like to know is if there is a command (i tried egrep but not with good results) to get only the bolded numbers (both in parenthesis and out) to a file and show them like this
Code:
114.86.196.165
66.26.105.245
84.19.181.228
...

I tried this command but i can only get the one in parenthesis, if i don't use parenthesis it messes up.

Code:
egrep -o "\([0-9]*.[0-9]*.[0-9]*.[0-9]*\)" scan.txt > egrep.txt


Thank you very much in advance!

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.
# 2  
It seems you have a GNU grep so if pcres are available:

Code:
grep -Po '(\d+\.){3}\d+' infile

This User Gave Thanks to radoulov For This Post:
# 3  
thanks

Thank you very very much!

Have a nice day, u surely made mine!

Oh and sorry for not using the code tags, i'll be sure to do that the next time.
# 4  
POSIX grep:
Code:
grep -Eo '([0-9]+\.){3}[0-9]+' infile

This User Gave Thanks to Scrutinizer For This Post:
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Decimal numbers and letters in the same collums: round numbers

Hi! I found and then adapt the code for my pipeline... awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal... It works but I have also some problems... here my columns ... (7 Replies)
Discussion started by: echo manolis
7 Replies

2. Shell Programming and Scripting

Perl match multiple numbers from a variable similar to egrep

I want to match the number exactly from the variable which has multiple numbers seperated by pipe symbol similar to search in egrep.below is the code which i tried #!/usr/bin/perl my $searchnum = $ARGV; my $num = "148|1|0|256"; print $num; if ($searchnum =~ /$num/) { print "found"; }... (2 Replies)
Discussion started by: kar_333
2 Replies

3. UNIX for Dummies Questions & Answers

Print numbers and associated text belonging to an interval of numbers

##### (0 Replies)
Discussion started by: lucasvs
0 Replies

4. Shell Programming and Scripting

Regex/egrep matching numbers in brackets

Experts: I don't know that regular expressions will ever be easy for me, so if one of you guru's could help out, I'd appreciate it. I'm trying to match a line in our syslog, but I can't figure out how to match a number inside a bracket. This is what I'm trying to match. "Jul 16 00:01:34... (2 Replies)
Discussion started by: jdveencamp
2 Replies

5. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

6. UNIX for Dummies Questions & Answers

Replace US numbers with European numbers

hey, I have a file with numbers in US notation (1,000,000.00) as well as european notation (1.000.000,00) i want all the numbers to be in european notation. the numbers are in a text file, so to prevent that the regex also changes the commas in a sentence/text i thought of: sed 's/,/\./'... (2 Replies)
Discussion started by: FOBoy
2 Replies

7. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

8. UNIX for Dummies Questions & Answers

seperating records with numbers from a set of numbers

I have two files one (numbers file)contains the numbers(approximately 30000) and the other file(record file) contains the records(approximately 40000)which may or may not contain the numbers from that file. I want to seperate the records which has the field 1=(any of the number from numbers... (15 Replies)
Discussion started by: Shiv@jad
15 Replies

9. UNIX for Dummies Questions & Answers

search ")" with egrep - egrep: syntax error

Hi Guys, we have a shell script which basically query the Database which retrieves huge data and use the data with "egrep" . Now there is some data which contains characters like "abc)" and the same is used like below : "egrep (.+\|GDPRAB16\|GDPR/11702 96 abc)\|$ temp.txt" now while... (7 Replies)
Discussion started by: sagarjani
7 Replies

10. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies

Featured Tech Videos