Results 1 to 7 of 7
Hi, I want to make script that will add some links to pictures to xml file. It is script, that will save few ours of clicking in Tellico. I am ...
- 08-16-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 4
Help with text manipulating script.
Hi, I want to make script that will add some links to pictures to xml file. It is script, that will save few ours of clicking in Tellico. I am not very experienced script writer, so I will need some help.

Goals of my script:
Put links to images to xml file. Location of link depends on:
number of image ($n-$nnn),
item id in xml file (<numer>0001</numer>),
$s (this variable holds letter or letter+number that express side from which photography has been taken).
First - here is my concept:
1. I have xml file tellico.xml. I have some pictures named from 000$n-$s.JPG (00$nn-$s.JPG)to 0$nnn-$s.JPG (where $n=1-9, $nn=10-99, $nnn=100-999, $s=b, b2, d, p, t and so.)
2. I want to read part of tellico.xml file - from <entry id="0" > to <entry id="1" > (then delete last line) and save this text to file named - from 000$n.tmp to 0$nnn.tmp. Trick is, that number that is in line <entry id="0" > is not the number of picture, picture number is in variable <numer>0001</numer> between "entry id" tags. So before saving *.tmp files I want to read desired filename from "numer" field.
3. When I will have this tmp files, I want to put links there.
a) check if picture file exist
b) check if there is link already in tmp file
c) if not check "side from which photo had been taken" $s variable
d) write link to picture to good place (this part of is most clear for me)
4. Put tmp files together again (make new tellico.xml file). Delete all temporary files.
QUESTIONS:
1.) Do you think that my concept is OK? (I hope you understand what I meant, I am not native English speaker)
2.) How I can make this temporary files (how to search from <entry id="0" > to <entry id="1" > ).
Thank you very much! I am not expecting, that someone will write script for me! I will only ask some questions if my experiments will fall.
- 08-18-2007 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
welcome to the forum
> how to search from <entry id="0" > to <entry id="1" >
in awk, you can use a so-called range pattern:
/<entry id="0" >/,/<entry id="1" >/ { whatever }
to do whatever between those two. It might help if you
could post the file you wish to manipulate.the sun is new every day (heraclitus)
- 08-18-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 4
Thank you for help!
I am so glad, that You want to help me. I have so many work now, that any help is good for me. I had tried sed, and some combination of head, and so., but without good results, thank you for good tip!
Here is my file.
Strug krajnik
It is in polish, but I think, that You will understand structure without any problem. Again it is file from program Tellico. You will see, that first part of file, is where fields are declared (it is between <fields> and </fields>), in second part there are entries. In this script second part of file is interesting for me.
- 08-19-2007 #4Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
let's see whether we're making progress here. Using
"file" to name the monster
awk '/<entry id="0">/,/<entry id="1">/ { print }' <file
| tee tmp | grep numer | head -1 | cut -c8-11
gets "0002" as output, plus 42 lines in a file "tmp"
OK so far? Now:
1. you want to delete the last line in "tmp"
2. you want to rename the result "0002.tmp"
1. "head -n -1 <tmp >tmp2"
2. save 0002 in a file "n", use "A=`cat n`" to
set an environment variable; then try
"mv tmp2 $A.tmp"
this second part is kludgy, you can do betterthe sun is new every day (heraclitus)
- 08-20-2007 #5Linux User
- Join Date
- Aug 2006
- Posts
- 458
from what i see, don't think you need to use tmp files. you just want to put some links between the entry tags that start from 0 till 1 right? Show us where you want to put the links in the tellico.xml file. That is, show us the actual output of the "new" tellico.xml file format. The capabilities of awk is more than meets the eye.
- 08-21-2007 #6Just Joined!
- Join Date
- Aug 2007
- Posts
- 4
At the beginning, thank you all! To ghostdog74: I feel, that tmp files should not be necessary, but I have no idea how to do it without them.
Ok, I don't need to modify the file, because first half of file include images already. Look at:That is, show us the actual output of the "new" tellico.xml
<zdjecie-2>Photos/Strugi/0002-b.JPG</zdjecie-2>
for example.
There are tags:
<zdjecie-x> </zdjecie-x> (where x=1-7)
And trick is that I have images (in different subfolders - you can see them in picture links, that are already in the tellico.xml) named, f.e.:
0056-d.JPG
0111-p.JPG
...
Now let me show you the code:
<entry id="201">
<title>Tarka do prania</title>
<material>drewno, metal</material>
<numer>0193</numer>
<stan-zachowania>kompletny</stan-zachowania>
... (DELETED, NOT NECESSARY FOR THIS EXAMPLE)
<szerokosc>375</szerokosc>
<notatki>szerokość mierzona na dole</notatki>
<typ-cechy-charakterystyczne>tarka wykonana ze stopu ?<br/>obita drewnem</typ-cechy-charakterystyczne>
<zdjecie-2-opis>z boku</zdjecie-2-opis>
<zdjecie-3-opis>z góry</zdjecie-3-opis>
<zdjecie-4-opis>z przodu</zdjecie-4-opis>
<zdjecie-5-opis>z tyłu</zdjecie-5-opis>
<zdjecie-6-opis>szczegółu</zdjecie-6-opis>
<zdjecie-7-opis>szczegółu</zdjecie-7-opis>
</entry>
I have pictures for this entry in folder Photos/Tarki/ (this path is relative to tellico.xml file):
0193-b.JPG
0193-g.JPG
0193-p.JPG
0193-t.JPG
0193-s.JPG
0193-s2.JPG
Final result will be:
<entry id="201">
<title>Tarka do prania</title>
<material>drewno, metal</material>
<numer>0193</numer>
<stan-zachowania>kompletny</stan-zachowania>
... (DELETED, NOT NECESSARY FOR THIS EXAMPLE)
<szerokosc>375</szerokosc>
<notatki>szerokość mierzona na dole</notatki>
<typ-cechy-charakterystyczne>tarka wykonana ze stopu ?<br/>obita drewnem</typ-cechy-charakterystyczne>
<zdjecie-1>Photos/Tarki/0193-b.JPG</zdjecie-1>
<zdjecie-2-opis>z boku</zdjecie-2-opis>
<zdjecie-2>Photos/Tarki/0193-b.JPG</zdjecie-2>
<zdjecie-3-opis>z góry</zdjecie-3-opis>
<zdjecie-3>Photos/Tarki/0193-g.JPG</zdjecie-3>
<zdjecie-4-opis>z przodu</zdjecie-4-opis>
<zdjecie-4>Photos/Tarki/0193-p.JPG</zdjecie-4>
<zdjecie-5-opis>z tyłu</zdjecie-5-opis>
<zdjecie-5>Photos/Tarki/0193-t.JPG</zdjecie-5>
<zdjecie-6-opis>szczegółu</zdjecie-6-opis>
<zdjecie-6>Photos/Tarki/0193-s.JPG</zdjecie-6>
<zdjecie-7-opis>szczegółu</zdjecie-7-opis>
<zdjecie-7>Photos/Tarki/0193-s2.JPG</zdjecie-7>
</entry>
As you see, the key that will put the links in right place is <numer> tag (not entry id!) and the name of file. Where to put link is also decided by second part of filename 193-d.JPG.
Here is the key. We have:
<zdjecie-x>
0193-y.JPG
then:
+--+--+
| x | y |
+--+--+
| 1 | b |
| 2 | b |
| 3 | g |
| 4 | p |
| 5 | t |
| 6 | s |
| 7 | s2 |
+--+--+
And I forget, not always there will be all 6 pictures (7 links), sometimes, there will be only one (but It will be not problem - I will test if file exist).Last edited by ernierasta; 08-21-2007 at 08:11 AM. Reason: I forget ;-), little mistakes.
- 08-31-2007 #7Just Joined!
- Join Date
- Aug 2007
- Posts
- 4
Almost done!
Ok, I am almost done with my script. Thank you for help (especially this awk trick), it allow me to write the script! Now I must think about merging tmp files to new tellico.xml. I will post whole script, when it will be finished, maybe someone will find it useful.


Reply With Quote