Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: File Find/Replace with the replacement coming from part of earlier matched string

by Kenosis (Priest)
on Feb 05, 2013 at 13:51 UTC ( #1017166=note: print w/replies, xml ) Need Help??

in reply to File Find/Replace with the replacement coming from part of earlier matched string

One option is to create a directory in your log files' directory for the prepped log files, so the originals aren't altered. Given that the log files' format is as shown, consider the following which writes prepped files into a directory called prepped:

use strict; use warnings; my $pcName; local $/ = ''; # paragraph mode for my $file (<*.log>) { open my $fhIN, '<', $file or die $!; open my $fhOUT, '>', 'prepped/' . $file or die $!; while (<$fhIN>) { chomp; print $fhOUT $_ if /\n/; # first two file lines next if /^(PCName:\s+.+)/ and $pcName = $1; # pc name & next print $fhOUT "\n\n$pcName\n$_"; # print pc name & command } close $fhIN; close $fhOUT; }

Sample file output from your data:

PCName: Foo1 Command1:dfie PCName: Foo1 Command2:dfo PCName: Foo1 Command3:dfum PCName: Foo2 Command1:dfie PCName: Foo2 Command2:dfo PCName: Foo2 Command3:dfum

The fileglob operator <*.log> is used to get the list of files in the log directory; you may need to change the file extension.

Hope this helps!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017166]
[ambrus]: (Alternately a deep source dive and then rewrite that event loop to make it better, and then as a bonus you get an idle method.)
[ambrus]: The 0.2 seconds wakeup is likely a workaround for some bug, but I can't guess what bug that is.
[ambrus]: It's been there since Prima 1.00 iirc
[Corion]: Hmmm... Weird. Maybe it needs that for doing its timers or something. Still weird.
[Corion]: But I guess I'll find out soonish, as my application seems to use Prima for more than just displaying the OpenGL output soonish ;))
[ambrus]: No, I think the timers are handled fine in the event loop, as far as I can see.
[Corion]: So far, I liked Prima quite well as it simply seems to do what I want even if it has an upside-down coordinate system. But it installs from CPAN out of the box and is cross-platform

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2016-12-09 10:35 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (150 votes). Check out past polls.