On Wednesday, February 10, 2016 05:02:46 PM Mick wrote:
> I've been struggling to parse/split/substitute some names and numbers using
> a spreadsheet and think that this task may be easier to achieve using
> conventional *nix tools. The problem is I wouldn't know where to start.
> 
> I have a directory with loads of images.  Each image file name has a
> description comprising hyphen-separated words and a part number, also hyphen
> separated; e.g.:
> 
> some-description-with-words-012-63099.jpg
> 
> The number and length of the words change for each file.  The part number
> always has two components separated by a hyphen, but may also change in
> length and acquire more/fewer digits.
> 
> I need two outputs:
> 
> 1. the description + " (per M²)", like so:
> 
> some-description-with-words (per M²)
> 
> 2. the part number, but replacing the hyphen with "/", like so:
> 
> 012/63099
> 
> 
> I can list the directory contents and redirect all image file names into a
> txt file.  What I am looking for is some additional steps I can pipe it
> through to obtain the two outputs, either in the same file or different
> files.  These file(s) are then imported into a spreadsheet template and
> manipulated, before the result is ultimately exported from the spreadsheet
> and uploaded to a server as a CSV file.
> 
> Is this parsing, splitting and substitution exercise achievable?  Any
> suggestions to try out?

Does this help:

echo "some-description-with-words-012-63099.jpg" | sed 
's/\(.*\)-\(.*\)-\(.*\).jpg$/desc=\1   (per M²) part= \2\/\3 /'

(All on 1 line)

I get the following as output:

desc=some-description-with-words (per M²)  part= 012/63099


--
Joost

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to