1 |
Hi Mick! |
2 |
|
3 |
Am Mittwoch, 10. Februar 2016, 17:02:46 CET schrieb Mick: |
4 |
> I've been struggling to parse/split/substitute some names and numbers using |
5 |
> a spreadsheet and think that this task may be easier to achieve using |
6 |
> conventional *nix tools. The problem is I wouldn't know where to start. |
7 |
|
8 |
I was taught by other linux users (mostly fanatic KISS people from Archlinux |
9 |
:D) to use as less different tools and therefor dependencies for a script/ |
10 |
shell command as possible. In your case, simple bash might be even enough: |
11 |
|
12 |
Check the bash man page for "PARAMETER EXPANSION" (these $ |
13 |
{foo...somethingspecial} instead of $foo). |
14 |
|
15 |
> I have a directory with loads of images. Each image file name has a |
16 |
> description comprising hyphen-separated words and a part number, also hyphen |
17 |
> separated; e.g.: |
18 |
|
19 |
> some-description-with-words-012-63099.jpg |
20 |
> |
21 |
> The number and length of the words change for each file. The part number |
22 |
> always has two components separated by a hyphen, but may also change in |
23 |
> length and acquire more/fewer digits. |
24 |
> |
25 |
> I need two outputs: |
26 |
> |
27 |
> 1. the description + " (per M²)", like so: |
28 |
> |
29 |
> some-description-with-words (per M²) |
30 |
|
31 |
Just save both informations to one variable, then print/echo the value of |
32 |
these variables (something like "echo $VAR1 $VAR2" or even "echo $VAR1 (per |
33 |
M²)". |
34 |
|
35 |
> 2. the part number, but replacing the hyphen with "/", like so: |
36 |
> |
37 |
> 012/63099 |
38 |
|
39 |
Again, parameter substitution might work. :-) |
40 |
|
41 |
> I can list the directory contents and redirect all image file names into a |
42 |
> txt file. What I am looking for is some additional steps I can pipe it |
43 |
> through to obtain the two outputs, either in the same file or different |
44 |
> files. These file(s) are then imported into a spreadsheet template and |
45 |
> manipulated, before the result is ultimately exported from the spreadsheet |
46 |
> and uploaded to a server as a CSV file. |
47 |
> |
48 |
> Is this parsing, splitting and substitution exercise achievable? Any |
49 |
> suggestions to try out? |
50 |
"Everything is possible"™ |