2

Good Evening,

I am attempting to utilize multiple character classes at the same time without success. Given a column that contains the URI of HTTP traffic, I want the REGEX to identify lines that where the URI field contains a string of text 6-10 characters long that contains numbers AND lower case letters...at least one of each, but NOT upper case letters.

This search will NOT be bounded to a specific character or part of the string...

Test strings:

aasd4567
9f7g6s5df
0hjksdf73
123456789
12345/1234a
Wordswords
W0rdsW4rds
aasd4/567af
9f7g6s5dfasdf
0hjks/asdf
12345/1234asd
Wordswords12
W0rdsW4rds12312312

I had hoped I could utilize a little boolean with brackets, ie:

awk --re-interval '$1 ~ /([0-9]+&[a-z]+){6,10}/'

But that doesn't work. And obviously, combining them won't work either because

awk --re-interval '$1 ~ /[a-z0-9]{6,10}/'

still returns strings without any numbers and without any lowercase letters.

I even tried to find ways to combine [[:lower:]] and [[:digit:]] but faced the same issue as the first example above.

I'm sure it's a super easy fix, what am I missing? I'm not against using gawk/grep/sed/etc, whatever is the most efficient tool for this task.

Thanks

0

1 Answer 1

4

If I understood your question correctly, you could use match first, then RSTART and RLENGTH to extract the matching string and then examine it for the presence of a digit AND a character, thus:

awk  --re-interval '{match($1, /[[:lower:][:digit:]]{6,10}/); 
  x=substr($1, RSTART, RLENGTH)}; x ~ /[[:lower:]]/ && x ~ /[[:digit:]]/' test_strings

Given your test strings this yields:

aasd4567
9f7g6s5df
0hjksdf73
9f7g6s5dfasdf
12345/1234asd
Wordswords12
W0rdsW4rds12312312
2
  • That actually works great, but I wonder if the match command might be too processor intensive. Might there be a more streamlined way to do it? The files I am looking through are 100k+ lines long...
    – user112802
    May 14, 2016 at 4:16
  • @user112802, give it a shot, you will be surprised
    – iruvar
    May 14, 2016 at 4:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .