[lug] Odd Shell Script Queries

Chip Atkinson chip at pupman.com
Tue Jan 18 15:42:02 MST 2005



On Tue, 18 Jan 2005, Matt Thompson wrote:

> Oh knowledgeable ones, I have a couple shell script queries.  First, the
> one I believe there might be an answer to.
> 
> Is there an easy way to batch-convert filenames from using dots as
> separators to underscores *while leaving the final dot*?  That is, I
> know I can do:
> 
> > echo "ibr-.355.3graph.notitle.pdf"| tr '\.' '_'
> ibr-_355_3graph_notitle_pdf

I'd pipe it through sed myself: 
echo ibr-.355.3graph.notitle.pdf | sed -e 's/\./_/g' -e 's/_pdf$/.pdf/'


> 
> but now the final "." is an "_".  I'm sure I could use Perl or something
> to chomp off the last bit, do the translation, and re-concatenate the
> end back, but I thought I'd ask if someone here knew a nice way.  (If
> you're wondering, LaTeX is b0rking on my habit of using dots in
> filenames.)
> 
> 
> My second script question is a bit more involved.  Namely, at my work we
> have multiple printer queues.  Two are a LaserJet and Color LaserJet,
> with the Color one being more expensive.  I began to wonder if there was
> a script that parsed a PS or PDF file in such a way that only pages with
> color are sent to a color printer, while the rest are sent to the mono.
> I'm not enough of a PS/PDF guru to know if this is even possible, but
> for a large, mainly-text file (say a thesis) with a few color diagrams,
> it would be interesting to know if it exists.

If you can create the same document in color and black and white, you
could diff the two and look for kewords.  Then you could use grep to
search for them and if found print to color.

> 
> Thanks for the help,
> Matt
> 
> -- 
> Learning just means you were wrong and they were right. - Aram
>    Matt Thompson -- http://ucsub.colorado.edu/~thompsma/
>    440 UCB, Boulder, CO  80309-0440
>    JILA A510, 303-492-4662
> 




More information about the LUG mailing list