[lug] Odd Shell Script Queries
Scott Kruger
kruger at txcorp.com
Tue Jan 18 17:52:43 MST 2005
Here is an example bash script that I created for dealing with filenames
and extensions. It should be straightforward to modify it and stick it
into a for loop to do what you want.
#!/bin/bash
file=root0009.eps
extension=${file##*.}
rootname=${file%.*}
rootnonum=${rootname%%[0-9]*}
number=${rootname#$rootnonum}
echo 'file name ' $file
echo 'extension' $extension
echo 'root name ' $rootname
echo 'root w/o number ' $rootnonum
echo 'number ' $number
On Tue, Jan 18, 2005 at 03:42:02PM -0700, Chip Atkinson did write:
>
>
> 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
> >
>
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
More information about the LUG
mailing list