Commavee

from John Minnihan, founder of Freepository.

Tech Tip: Multi-line Perl regex pattern match

Yesterday, I encountered an analysis issue that appeared to be resolvable with a simple pattern replacement technique.  This turned out to be a bit more complex than estimated, as the pattern spanned multiple lines and I struggled to get the regex constructed to match this use case.

I finally figured it out, and although the overall problem remains unresolved (it has many layers), this particular part works well.  My error was in how I viewed use of  /s and /m as mutually exclusive; they aren’t of course, and I have made that mistake one other time over the years.   I also hadn’t set the input record separator ($/) to paragraph read mode.   I’m posting details here to document my specific usage.

Assumptions:

  • A literal pattern exists that is present in multiple places in a file
  • The literal pattern spans multiple lines in the file
  • Literal pattern is

    • Node-path: branches/%%BRANCHES%%
    • Node-kind: dir
    • Node-action: add
  • Perl is being used to read the file and current line of file is $line
  • Objective is to delete all occurrences of this pattern from the file one $line at a time

Here’s how I did that:

[read the file & crawl thru the lines]

$/ = ”;

$line =~ s/^Node-path:\sbranches\/%%BRANCHES%%.*?^Node-kind:\sdir.*?^Node-action:\sadd.*?//sm;

Tags: , ,

Popularity: 48% [?]

Posted 2 weeks, 1 day ago at 9:56 am.

Comments

Quick file & directory cleanup tools

Every sys admin needs to quickly free up disk space from time to time, and here are two well-tested scripts I use for exactly this purpose.

The first is a simple command-line use of exec that uses find to construct of list of matching file names, in this case all gzipped tarballs, and then runs the rm command on them.  The curly braces "{}" act as a holder for each file name from the list, and the trailing "\" is used to escape the ";", so that it is passed to find as a literal command terminator.

#find . -name *.tar.gz -exec rm {} \;

You may find (pun intended) that you need a slightly more sophisticated way to construct the list of things to remove.  For example,  to recursively delete all files & directories from an arbitrary depth in the file-system, except for special files or directories.  To accomplish this, I use a small Perl utility I wrote that uses the File::Find module. 

Here is the actual script I use generalized out with a fake $top and /some-pattern-to-exclude/. This script will crawl down (actually the direction that finddepth goes is up) a list of files & directories, and unless the pattern is matched, each file in the directory & then the directory itself is deleted.

How does this work?  Pretty simple – the File::Find module loads some routines, one of which is finddepth. The first argument it expects is a routine to run against all files & directories found, starting at the location named in the second argument.  The wanted routine is run on each element in finddepth’s list & you can use  finddepth’s variables to make your wanted routine smarter.

Tags: , ,

Popularity: 8% [?]

Posted 2 weeks, 4 days ago at 6:49 pm.

Comments

Don’t install TortoiseSVN v 1.6.2?

A friend of mine forwarded this to me a few days ago; I filed it away under ‘refer to later’.   Later just arrived, as I saw someone tweet about a TortoiseSVN issue on Vista.

I’m relaying this here in the hope that it saves folks the hassle of figuring it out themselves.

I [installed TortoiseSVN 1.6.2] this morning, and it just failed silently, After digging out some logs etc, I found the very helpful Microsoft message "Application did not start because its side-by-side configuration was not correct"
That has to be one of the most non-enlightening error messages of all time.

I had come across that myself before with ScreenCap, and I was able to figure out that it has some mysterious connection to the .NET framework. However, my work-around was pretty ugly, and not useful in this case.

My recovery for tortoise is that I had to uninstall the new version, restart 3 times to make sure that windows forgot about it it, and then install the older (1.6.1) version.

From previous experience with this side-by-side nonsense, this seems to be Vista specific because I’ve never seen that message in an XP machine. Interestingly enough, I didn’t see a bug report on the tortoise site, but I only did a cursory look through the list.

Tags: , ,

Popularity: 12% [?]

Posted 1 month, 2 weeks ago at 6:27 pm.

Comments

Glue Conference 2009

The inaugural Glue Conference was held this week & it was, as expected, fantastic.

When I saw Eric last November at Defrag, he told me he was starting another conference.  My one sentence response was ‘let me know how I can help’.  He promised he would.

Fast forward a few months and there I was at Glue as both a sponsor and panel moderator.  From a business perspective, it was time & money well spent, as I had the opportunity to meet & socialize with some truly amazing technologists & entrepreneurs.   The venue at the Hyatt is very well suited for conferences, and in the heart of downtown Denver, is easily accessible via taxi & light rail.

I’ll leave the deep analysis to others for now, but I do want to share with you the quote I left for Eric on the post-conference survey.  I think it speaks for itself:

"What an amazing group of people. Where else could I have had a one-on-one conversation with Bob Frankston while Mitch Kapor was standing less than 20 feet away, after having had drinks the evening before with a group that included an America’s Cup winner (hey T.A.!)."

Tags: ,

Popularity: 7% [?]

Posted 1 month, 2 weeks ago at 8:58 am.

Comments

Astroturfing

Please don’t waste your time – and mine – astroturfing here.  I’ll just delete the comments as soon as I see them.

I really, really welcome genuine comments on any of the posts I’ve ever written (the ajax logfile tailer & the elliptical mileage calculation posts are especially popular), and I read them all.  But the moment I determine you’re fronting a comment for advertising purposes, it gets deleted without a second thought.

Save yourself the trouble, really.

Tags:

Popularity: 8% [?]

Posted 2 months, 3 weeks ago at 6:52 am.

Comments