simple regex question

Kevin D. Clark kclark at elbrysnetworks.com
Thu Jan 11 14:57:38 EST 2007


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.




More information about the Discuss mailing list