Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use sed and regexp to replace with alternates

Status
Not open for further replies.

dominic3

IS-IT--Management
May 24, 2005
2
GB
Hi folks, I am trying to improve on this lumpy piece of sed and regexp (my first try). I am processing the output of a vast image library. Some image files have names like [tt]dsc001597.jpg[\tt] others are like [tt]dsc002567a.jpg[\tt]
and I need to output a file containing comma separated records of the form <Gallery>,<ImageId[.ImageSubId]> e.g.:

[tt]Gallery1,1597
Gallery2,2567.01
Gallery2,5070.02
...[\tt]
Code:
#!/bin/bash
dirname=Gallery2
ls -al *.* \
        | sed  y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
        | sed "/jpg$/ \
                s/\(.\{55\}\ \)\(.*\)/$dirname,\2/g
                s/\([a-z]*,\)[a-z]*\(0*\)\([0-9]*[a-z]*\).jpg/\1\3/g
                s/\([a-z]*,[a-z]*[0-9]*\)a/\1.01/g
                s/\([a-z]*,[a-z]*[0-9]*\)b/\1.02/g
                s/\([a-z]*,[a-z]*[0-9]*\)c/\1.03/g
                s/\([a-z]*,[a-z]*[0-9]*\)d/\1.04/g
                s/\([a-z]*,[a-z]*[0-9]*\)e/\1.05/g
                s/\([a-z]*,[a-z]*[0-9]*\)f/\1.06/g"
I would like to use POSIX classes for the upper to lowercase replacement and I would like a lookup function that allows me to neatly replace: a with .01, b with .02 etc.

TIA

 
Oh dear, I terminated the [tt]Monospaced text[/tt] with incorrect TGML tags. Sorry. :~/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top