Thursday, May 31st, 2007
We have an internal Maven repository at my company. This allows us to have an official repo of “approved” artifacts that developers can use. (For example, GPL’ed projects might not be legal to use for our purposes.)
Anyway, we use a script to pull down artifacts from the official Maven repository (http://repo1.maven.org/maven2/). However, the script does not overwrite, and sometimes metadata files are duplicated. The resulting directory listing for an artifact might look like this:
$ ls -1 1.0 1.0-rc1 maven-metadata.xml maven-metadata.xml.1 maven-metadata.md5 maven-metadata.md5.1 maven-metadata.sha1 maven-metadata.sha1.1
Obviously fixing the script to overwrite would solve the problem of these “.1″ files. But, I was curious as to how I could easily move the “.1″ files to their appropriately named counterparts. My newfound love for xargs made me think that I could do this in one cool command-line statement. Here’s what I came up with:
ls -1 *.1 | sed 's/.1//' | xargs -i mv {}.1 {}
Broken down:
1. I pass the “-1″ flag to ls, which tells it to print each item on a separate line. I filter ls to only show files that match the “*.1″ pattern.
2. Each line of output from ls is piped into sed, which just simply substitutes nothing for “.1″. We have constructed the desired file name.
3. Now, I can pipe each of these desired file names into xargs, and use the -i flag to substitute the standard input to the {} token.
Maybe there’s a completely obvious way to do this that I haven’t run across, but, like I said — newly discovered love for xargs, and everything looks like it can be piped into it

February 25th, 2008 at 5:12 pm
[…] I was recently seeing how well a fairly long, extremely specific blog title was indexed by Google. My general thinking has been that niche titles will appear high in search indices when Googled word-for-word. That is, even without surrounding the query in quotation marks, I would expect that a Google search for: […]