D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [LUG] any bash wizards?



> how do i match files with .JPG and maybe even .Jpeg too ? anyone with a
> regexp for maybe all types of picture extensions lower and upcase?! :)

You could experiment with regexp like [Jj][pP][gG]..... but that is
going to be a pain.

Last time I did something like this it was posix shell - I just found
the file names converted to upper case, and tested the new upper case
variable against the interesting cases.

Alas Bash seems to lack a 'declare' that declares a variable uppercase
<First weakness I spied compared to a certain proprietary POSIX shell).

So if you did this your have to call 'tr' everytime, which would be
inefficent but easy, or write your own 'uppercase' routine using arrays
which would be efficient but hard.

The quick to write and slow to run version would look something
like..... But compared to graphical manipulation the extra shells are
probably insignificant.

for afile in `find . -type f blahblahblah`
do
  UPafile=`echo $afile | tr [a-z] [A-Z]`
  # Actually should use classes :lower: :upper: in case it runs in other
locale
  FNafile=`basename $UPafile`
  # Another one that might be done quicker
  END=`expr "$FNafile" : '.*\.\(.*\)'`
  # You can probably skip the FNafile step entire and use this on
UPafile.
  # Return what matches after the last "." ==== what do you get if there
is no dot?
  # I.E The file extension.
  if [ "$END" = "JPEG" -o ....]
--
lug-list - The Mailing List for the Devon & Cornwall LUG
Mail majordomo at lists.termisoc.org with "unsubscribe lug-list" in the
message body to unsubscribe.


Lynx friendly