Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

simple regex question



Dwight E Chadbourne <dwighte.chadbourne at stopandshop.com> writes:

> Hi all.  I want the 20 digit hash in this text.
>
> d5:filesd20:xxxxxxxxxxxxxxxxxxxxd8:completei2e10:downloadedi0e10:incompletei4e
> 4:name12:xxxxxxxxxxxxee5:flagsd20:min_request_intervali3600eee

One way to do this might be:

  perl -ne 'm{[^:]*:            # first field
              [^:]*:            # second field
              (.{20})           # third field; 20 digit hash (saved)
             }x && print "$1\n";'

Another would be like this:

  perl -F: -lane '($F[2] =~ /(.{20})/) && print $1'

  (not entirely regexp based)

Note:  the second line of your example input doesn't contain what you
describe to be a 20-digit hash, and I don't know what to do about
that.

Hope this helps.

Just another Perl hacker,

--kevin
-- 
GnuPG ID: B280F24E              Never could stand that dog.
alumni.unh.edu!kdc                   -- Tom Waits


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org