1 |
On Wednesday, February 10, 2016 05:02:46 PM Mick wrote: |
2 |
> I've been struggling to parse/split/substitute some names and numbers using |
3 |
> a spreadsheet and think that this task may be easier to achieve using |
4 |
> conventional *nix tools. The problem is I wouldn't know where to start. |
5 |
> |
6 |
> I have a directory with loads of images. Each image file name has a |
7 |
> description comprising hyphen-separated words and a part number, also hyphen |
8 |
> separated; e.g.: |
9 |
> |
10 |
> some-description-with-words-012-63099.jpg |
11 |
> |
12 |
> The number and length of the words change for each file. The part number |
13 |
> always has two components separated by a hyphen, but may also change in |
14 |
> length and acquire more/fewer digits. |
15 |
> |
16 |
> I need two outputs: |
17 |
> |
18 |
> 1. the description + " (per M²)", like so: |
19 |
> |
20 |
> some-description-with-words (per M²) |
21 |
> |
22 |
> 2. the part number, but replacing the hyphen with "/", like so: |
23 |
> |
24 |
> 012/63099 |
25 |
> |
26 |
> |
27 |
> I can list the directory contents and redirect all image file names into a |
28 |
> txt file. What I am looking for is some additional steps I can pipe it |
29 |
> through to obtain the two outputs, either in the same file or different |
30 |
> files. These file(s) are then imported into a spreadsheet template and |
31 |
> manipulated, before the result is ultimately exported from the spreadsheet |
32 |
> and uploaded to a server as a CSV file. |
33 |
> |
34 |
> Is this parsing, splitting and substitution exercise achievable? Any |
35 |
> suggestions to try out? |
36 |
|
37 |
Does this help: |
38 |
|
39 |
echo "some-description-with-words-012-63099.jpg" | sed |
40 |
's/\(.*\)-\(.*\)-\(.*\).jpg$/desc=\1 (per M²) part= \2\/\3 /' |
41 |
|
42 |
(All on 1 line) |
43 |
|
44 |
I get the following as output: |
45 |
|
46 |
desc=some-description-with-words (per M²) part= 012/63099 |
47 |
|
48 |
|
49 |
-- |
50 |
Joost |