Need some help with a grep regex

1 view
Skip to first unread message

pand0ra.usa

unread,
Nov 10, 2009, 7:39:55 PM11/10/09
to Regex
I have the following lines that I am trying to strip down to the first
33 characters using grep (I want to remove the binary addresses):

Minimum Host : 0.0.0.1
00000000.00000000.00000000.00000001
Maximum Host : 0.255.255.254
00000000.11111111.11111111.11111110


Here is what I have for grep but it is not working and I was hoping
someone here could help me.



subnet.exe 0.0.0.0/8 | grep -e="^.{32} Maximum\|Minimum"

inhahe

unread,
Nov 11, 2009, 1:46:50 AM11/11/09
to re...@googlegroups.com
maybe "((?:Minimum|Maximum) *: *\d*\.\d*\.\d*\.\d*).*"

maybe one problem could be that you need . to match newlines which requires special parameters (in general... i don't know linux)
but i didn't understand your regex since it matches 32 characters of anything and then maximum|minimum but it looks like maximum/minimum is supposed to be the first part of the string

eugeny....@gmail.com

unread,
Nov 11, 2009, 2:02:56 AM11/11/09
to Regex


On Nov 11, 10:46 am, inhahe <inh...@gmail.com> wrote:
> maybe "((?:Minimum|Maximum) *: *\d*\.\d*\.\d*\.\d*).*"
>

perfecting further ...
^M(?:ax|in)imum Host *\: *\d{1,3}(\.\d{1,3}){3} *$

pand0ra.usa

unread,
Nov 11, 2009, 11:29:18 AM11/11/09
to Regex
Hummm..... couldn't get either to produce any results.

On Nov 11, 12:02 am, "Eugeny.Satt...@gmail.com"

inhahe

unread,
Nov 11, 2009, 11:30:45 AM11/11/09
to re...@googlegroups.com
could it be a newline issue?

Eugeny Sattler

unread,
Nov 12, 2009, 4:28:31 AM11/12/09
to re...@googlegroups.com
Check what things from the standard syntax you grep version supports
and what not.
I am under Windows XP where FINDSTR command supports limited number
regex operators.

For example I was quite surprised to know that it does not support
quantifiers, alternation construct, optional sign "?". You can not use
\d, you have to use [0-9] and who knows what more is missing there.
It is easier to list what it supports than what it doesn't.

So if I want 3 or 4 digits port number, I can not use \:[0-9][0-9][0-9][0-9]?
I can not use \:[0-9]{3,} either...

While searching for 4-digit port numbers works OK.

C:\WIN>netstat -an | findstr 127.*\:[0-9][0-9][0-9][0-9]

TCP 127.0.0.1:1042 0.0.0.0:0 LISTENING
TCP 127.0.0.1:1734 127.0.0.1:2424 TIME_WAIT
TCP 127.0.0.1:1737 127.0.0.1:2431 TIME_WAIT
TCP 127.0.0.1:1738 127.0.0.1:2435 TIME_WAIT
TCP 127.0.0.1:1739 127.0.0.1:2437 ESTABLISHED
TCP 127.0.0.1:1740 127.0.0.1:2440 ESTABLISHED
TCP 127.0.0.1:2437 127.0.0.1:1739 ESTABLISHED
TCP 127.0.0.1:2440 127.0.0.1:1740 ESTABLISHED
UDP 127.0.0.1:1025 *:*
UDP 127.0.0.1:1030 *:*
UDP 127.0.0.1:1900 *:*

--------------------------------------------------------------

If it is OK in your situation, export your output to a text file and
process it there with a text editor allowing full featured regexes.

--
Regards, Eugeny

Reply all
Reply to author
Forward
0 new messages