From tanner at real-time.com Tue Feb 13 00:47:15 2001 From: tanner at real-time.com (Bob Tanner) Date: Mon Jan 17 14:29:19 2005 Subject: [TCLUG-DEVEL] Just me or problems with CVS? Message-ID: <20010213004715.B25088@real-time.com> Is it me or is there problems with CVS? I tried an update tonight, get the boltzmann password thingie and it just hangs there. I can ping and traceroute to blotzmann, but no cvs access. -- Bob Tanner | Phone : (952)943-8700 http://www.mn-linux.org | Fax : (952)943-8500 Key fingerprint = 6C E9 51 4F D5 3E 4C 66 62 A9 10 E5 35 85 39 D9 From mjn at umn.edu Wed Feb 21 11:46:30 2001 From: mjn at umn.edu (mjn) Date: Mon Jan 17 14:29:19 2005 Subject: [TCLUG-DEVEL] Perl thing... Message-ID: I am looking to walk a directory structure, look at all the files ending in .html, and examine them for a bit of text and replace that text if its found. Awhile ago someone was kind enough to answer me for doing something like this if all of the files are in a certain directory but I haven't found a way to do this recursively. I tried this: perl -pi.bak -e 's/bob/dick/' testing/. But that doesn't seem to work. If this command would work like I think it should and it could be made only to affect a certain file extension, that would rule. So is there something I am missing or should I start writing something a little bigger for the job? ____________________________ Mike Neuharth ADCS Technology Specialist http://www.umn.edu/adcs E-Mail : mjn@umn.edu Page Mail : 6126486512@page.metrocall.com http://supermonkeycollider.dyndns.org/ ____________________________ From cbidler at talkware.net Wed Feb 21 13:17:39 2001 From: cbidler at talkware.net (Chris Bidler) Date: Mon Jan 17 14:29:19 2005 Subject: [TCLUG-DEVEL] Perl thing... References: Message-ID: <3A941453.7040305@talkware.net> mjn wrote: > I am looking to walk a directory structure, look at all the files ending > in .html, and examine them for a bit of text and replace that text if its > found. > > Awhile ago someone was kind enough to answer me for doing something like > this if all of the files are in a certain directory but I haven't found a > way to do this recursively. > > I tried this: > > perl -pi.bak -e 's/bob/dick/' testing/. > > But that doesn't seem to work. If this command would work like I > think it should and it could be made only to affect a certain file > extension, that would rule. > > So is there something I am missing or should I start writing something a > little bigger for the job? > I'm sure there *is* a way to write a one-liner to do this job, but I'm not convinced that you should attempt it. To recurse into directories, I use something like: sub checkdirs(){ #sorry, I don't know argument prototyping my $dir = $_[0]; #first argument passed in opendir(DH, "$dir") or die "$0: failed to open handle for $dir: $!\n"; my @listing = readdir(DH); closedir(DH); foreach my $file (@listing){ if((!-d $file) && ($file ~= /*\.html^/){ open(FH, "$file") or die $0: failed to open $file for read/write: $!\n"; while(){ $_ ~= s/dick/bob/g; } close(FH); } elsif ((!-d $file) || ($file ~= /$\.^/) || ($file ~= /$\.\.^/)) { #optional debugging output would go here } else { checkdirs($file); } } I apologize for problems with indentation; Mozilla isn't being very helpful. :) You might want some sort of debugging in the 'elsif' clause; the only things that should fall through to it are '.', '..', and anything that doesn't end in '.html', but isn't a directory. Hope that's helpful to you! -- <----------------------------------------------------------------------> Chris H. Bidler cbidler@talkware.net Random Task Handler, Sysadmin Group Universal Talkware Corp. "In any event, is a O^(log N) search that returns the wrong answer really better than an O^N search that returns the right answer?" <----------------------------------------------------------------------> From crumley at belka.space.umn.edu Wed Feb 21 12:46:02 2001 From: crumley at belka.space.umn.edu (Jim Crumley) Date: Mon Jan 17 14:29:19 2005 Subject: [TCLUG-DEVEL] Perl thing... In-Reply-To: ; from mjn@umn.edu on Wed, Feb 21, 2001 at 11:46:30AM -0600 References: Message-ID: <20010221124602.A7269@baker.space.umn.edu> On Wed, Feb 21, 2001 at 11:46:30AM -0600, mjn wrote: > I am looking to walk a directory structure, look at all the files ending > in .html, and examine them for a bit of text and replace that text if its > found. > > Awhile ago someone was kind enough to answer me for doing something like > this if all of the files are in a certain directory but I haven't found a > way to do this recursively. > > I tried this: > > perl -pi.bak -e 's/bob/dick/' testing/. Try: find testing/ -name "*.html" -print -exec perl -pi.bak -e 's/bob/dick/' {} \; find directory -name "*.html" - finds all files below the given directory with the suffix .html -print - print the name of the files found to standard out -exec - runs the specified command, where {} is replaced by the filenames that find found. \; - is piece of syntax whose reason for existing I never understood. HTH, Jim -- Jim Crumley | crumley@fields.space.umn.edu | Work: 612 624-6804 or -0378 | From mjn at umn.edu Wed Feb 28 16:54:23 2001 From: mjn at umn.edu (mjn) Date: Mon Jan 17 14:29:19 2005 Subject: [TCLUG-DEVEL] Perl thing... Message-ID: Alright, am I stupid or what. I have this regexp: $_ =~ /foo.+bar/s or this one $_ =~ /foo.+bar/sm And I would expect either of them to find foo bar in a given text file. The problem I am having is that it is not matching. Is there something I am doing wrong? Am I stupid for trying to parse and compile stats from my logfiles? It feels like it. On the subject, I am trying to match blocks of text that look like this (mail logs from Mercury, ick!): HELO mail.house.leg.state.mn.us MAIL FROM: RCPT TO: DATA - 72 lines, 3977 bytes. QUIT - 0 sec. elapsed, connection closed Mon Feb 12 08:54:40 2001 Suggestions on methods? ____________________________ Mike Neuharth ADCS Technology Specialist http://www.umn.edu/adcs E-Mail : mjn@umn.edu Page Mail : 6126486512@page.metrocall.com http://supermonkeycollider.dyndns.org/ ____________________________ From esper at sherohman.org Wed Feb 28 17:06:09 2001 From: esper at sherohman.org (Dave Sherohman) Date: Mon Jan 17 14:29:19 2005 Subject: [TCLUG-DEVEL] Perl thing... In-Reply-To: ; from mjn@umn.edu on Wed, Feb 28, 2001 at 04:54:23PM -0600 References: Message-ID: <20010228170608.H1282@sherohman.org> On Wed, Feb 28, 2001 at 04:54:23PM -0600, mjn wrote: > Alright, am I stupid or what. > > I have this regexp: > > $_ =~ /foo.+bar/s > or this one > $_ =~ /foo.+bar/sm > > > And I would expect either of them to find > > foo > bar > > in a given text file. The problem I am having is that it is not matching. > Is there something I am doing wrong? Where is $_ coming from? Are you, perhaps, doing while () { $_ =~ /foo.+bar/sm ... } ? (If so, $_ will only contain one line ("foo\n" or "bar\n") at a time.) -- SGI products are used to create the 'Bugs' that entertain us in theatres and at home. - SGI job posting Geek Code 3.1: GCS d? s+: a- C++ UL++$ P++>+++ L+++>++++ E- W--(++) N+ o+ !K w---$ O M- V? PS+ PE Y+ PGP t 5++ X+ R++ tv b+ DI++++ D G e* h+ r y+ From mjn at umn.edu Wed Feb 28 17:16:55 2001 From: mjn at umn.edu (mjn) Date: Mon Jan 17 14:29:19 2005 Subject: [TCLUG-DEVEL] Perl thing... In-Reply-To: <20010228170608.H1282@sherohman.org> Message-ID: As of Feb 28, 2001, Dave Sherohman can be held liable for saying: > while () { > $_ =~ /foo.+bar/sm > ... > } > > ? (If so, $_ will only contain one line ("foo\n" or "bar\n") at a time.) Yep, that's the problem. Its likely rudimentary but, how do I get around this stupidness on my part? I haven't ever tried multiline pattern matching before... ____________________________ Mike Neuharth ADCS Technology Specialist http://www.umn.edu/adcs E-Mail : mjn@umn.edu Page Mail : 6126486512@page.metrocall.com http://supermonkeycollider.dyndns.org/ ____________________________ From esper at sherohman.org Wed Feb 28 18:26:28 2001 From: esper at sherohman.org (Dave Sherohman) Date: Mon Jan 17 14:29:19 2005 Subject: [TCLUG-DEVEL] Perl thing... In-Reply-To: ; from mjn@umn.edu on Wed, Feb 28, 2001 at 05:16:55PM -0600 References: <20010228170608.H1282@sherohman.org> Message-ID: <20010228182628.I1282@sherohman.org> On Wed, Feb 28, 2001 at 05:16:55PM -0600, mjn wrote: > Yep, that's the problem. Its likely rudimentary but, how do I get around > this stupidness on my part? I haven't ever tried multiline pattern > matching before... IIRC, your original request looked like you're parsing a file containing several distinct records with a recognizable pattern (I'll assume it's a line beginning with "START:") that indicates the beginning of a new record. I assume that you're only interested in matching data within a single record at a time. Based on this, you'll want to read each record in full into a single string, then run your regex against that string. I would probably (based only on the impressions and assumptions already stated) use something like: --- my $record_text = ''; while () { unless (/^START:/) { # Continuation of record in progress $record_text .= $_; } else { # Found a new record examine_record($record_text); $record_text = $_; } } # Last record won't be followed by a 'new record' marker examine_record($record_text); sub examine_record { my $record_text = shift; if ($record_text =~ /foo.+bar/sm) { ... } } --- (This should be considered to be perl-like pseudocode, as I have not actually run it.) -- SGI products are used to create the 'Bugs' that entertain us in theatres and at home. - SGI job posting Geek Code 3.1: GCS d? s+: a- C++ UL++$ P++>+++ L+++>++++ E- W--(++) N+ o+ !K w---$ O M- V? PS+ PE Y+ PGP t 5++ X+ R++ tv b+ DI++++ D G e* h+ r y+