sed'ing out newlines

nmeyers at javalinux.net nmeyers at javalinux.net
Mon Dec 15 14:54:38 EST 2003


On Mon, Dec 15, 2003 at 02:42:18PM -0500, Dan Barrett wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Monday 15 December 2003 12:56, nmeyers at javalinux.net wrote:
> > Is that all you want to do, or are you doing something else in your sed
> > script? I ask because I think it'll be expensive and slow (I haven't
> > used sed in awhile, but I think you'll end up having to load the entire
> > file into its memory). The "tr" utility can remove newlines much more
> > efficiently:
> 
> 
> I'm trying to assemble a CLASSPATH variable by reading in a file and 
> substituting out the newlines in favor of a colon and perhaps another 
> variable.
> In essence, I've just inherited a bunch of projects with sprawling directory 
> structures (esp. third-party JARs scattered all over the place).  I want to 
> be able to switch the value of CLASSPATH on the fly when moving from project 
> to project, so I thought one way to do it would be to have a file for each 
> project.  Each file would list directories or individual JARs to be included 
> in the CLASSPATH; hence when trying out different third-party components I 
> could just edit the relevant file.
> Does this sound rational, or have I entered molehill -> mountain territory?

This is a perfectly reasonable approach. Now that I understand the
problem a bit, you can ignore my earlier suggestion about the "tr"
utility - you need a scripting language.  And whatever logic you end
up needing to write, you'll find much easier to figure out, maintain,
and improve in Perl than in sed - my own bias, perhaps, but I think it's
widely shared :-).

It's a fairly simple matter of Perl programming to take a list of
directories and build a CLASSPATH out of the .jars and .zips living in
those directories. I do something similar in a Java product deployment
of my own.

Nathan



More information about the Discuss mailing list