[Chicago-talk] /i resets $1 on failed matches?
Andy_Bach at wiwb.uscourts.gov
Andy_Bach at wiwb.uscourts.gov
Wed Jul 14 11:14:58 CDT 2004
Hi folks,
[From a couple other lists we have the question]
>> Does anyone know how I can get just the IP address out from lots of
entries,
>> below is just two of them, there is about 2000 like this. Is there a
flash
>> grep which can be used?
bash-2.03$ cat b.txt
job_xml
S<job jobID="77042" type="SNMPSet"><task taskID="1"
type="SNMPReset_DOCSISExperimental"><devicedescriptor><devicetype><attr
name="type">snmp</attr></devicetype><deviceinstance><attr
name="hostname">10.138.150.188</attr><attr name="hostport">161</attr></dE
S<job jobID="90713" type="SNMPSet"><task taskID="1"
type="SNMPReset_DOCSIS"><devicedescriptor><devicetype><attr
name="type">snmp</attr></devicetype><deviceinstance><attr
name="hostname">10.97.17.21</attr><attr
name="hostport">161</attr></deviceinstance><E
>> Just need the Ip address.
> This is the answer that was sent in:
cat b.txt |
perl -ne '/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/i;
print "$1\n" if $1;'
> Now my question.... why did I need to put the "i" at the end of the
regex?
> Without it, the script produced:
10.138.150.188
10.138.150.188
10.138.150.188
10.138.150.188
10.97.17.21
10.97.17.21
> with it, it produced:
10.138.150.188
10.97.17.21
[end other list quotes]
I pointed out that:
cat b.txt |
perl -ne 'print "$1\n"
if /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;'
was a slightly "better" idea, as $1 wasn't being reset on a failed match
and so existed/causes the print. I can't find where/why the /i resets $1
on a failed matches though. The "Owls" book does talk about the expense
and copies made with '/i' and how it ends up w/ at least 2 REs (original
and a lower case version) but I don't have a debug version of perl to try
-Dr on to see the difference (assuming I could understand the output).
Anybody have an answer?
a
Andy Bach, Sys. Mangler
Internet: andy_bach at wiwb.uscourts.gov
VOICE: (608) 261-5738 FAX 264-5932
Beware of bugs in the above code; I have only proved it correct, not tried
it. -- Donald Knuth
More information about the Chicago-talk
mailing list