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
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.
Freepository is 10 years old in May & a new site design has been released to correspond with the anniversary.
Perhaps the biggest change in this release is that of no more new CVS accounts. While this saddens me a bit (we were the first to offer hosted CVS accounts way back in our alpha in May 1999), we’re confident we’re offering what the majority of our visitors want – hosted Subversion. And existing CVS accounts aren’t going anywhere – they’re exactly where they were last week and you can access them exactly the same way today.
Almost two years, I wrote a log file viewer that asynchronously tails a log file & updates a <div> inside a a page. As a courtesy to other engineers, I posted about it.
The funny thing about that is, although it is one of my most widely *viewed* posts, there are only a few comments. This leads me to conclude that the highly technical software engineers who’ve arrived at the post via a search are very interested in learning how I’ve done it (check here for the post & you’ll see an explanation, the source code & a working example), but they aren’t interested in having a conversation.
Someone else1 pointed out that Google searches dropped off dramatically during Obama’s Inauguration, while both Twitter & Facebook usage skyrocketed. This elicits the position that search is not a social application; it is performed as & when needed purely for information. I’m fascinated by the very real anecdotal evidence of this in my own server logs.
1 Sarah Lacey http://www.sarahlacy.com/sarahlacy/2009/01/google-dethroned.html
I’ve done more systems work today than is typical.
The mail server, after a brutal spam thrashing that began 24 hours ago (see below), has been turned back on with updated Spamassassin rules, enhanced by the always awesome Mailscanner interface. I’ve also completed the earlier-mentioned theme update.
And, moments ago, I reenabled twitterfeed. I’m feeling like I’m getting close to convergence of my online presence. If I could eliminate email… that’d be nice.