[Tutor] newbie question about grep in Python

Eric Culpepper eculpepper at hcc-care.com
Tue Feb 10 17:26:11 EST 2004


I'm trying my best to learn Python and I'm going through some shell scripts attempting to write Python versions of these scripts. I stumbled on this piece of a script and I'm struggling to figure out a method of doing this in Python.

#!/bin/sh
o_date=`strings /shc1/$1/$2 2> /dev/null | grep Date | egrep "\#V\#|\@\(\#\)" \
        | sed 's/^\\$//' | awk 'BEGIN {FS="$"} {printf("%s\n",substr($2,6))}'`
echo "o_date is $o_date"

This hack-job script is used to look at compiled programs and get pull the last modified date from them. Here's a sample output from strings parsing one of these files. (In particular the date field between the #V# and #V# is the date I'm interested in.)

cAModule  $Header:rxrmon.s, 59, 1/8/04 3:38:55 PM, Roxanne Curtiss$
c SCCS Library $Workfile:rxrmon.s$
Version $Revision:59$
Date $Date:1/8/04 3:38:55 PM$
#V#$Revision:59$#V#
#V#$Date:1/8/04 3:38:55 PM$#V#
- RXRMON - 2jan87 - RM


I've looked through the Regular Expression HOWTO, python.org's searchable website and I must be missing the forest because of the trees because I can't seem to wrap my mind around doign this in Python. Any tips or suggestions would be very very helpful!

Thanks

Eric Culpepper

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040210/ef8c55d5/attachment.html


More information about the Tutor mailing list