LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Assign a value (https://www.linuxquestions.org/questions/programming-9/assign-a-value-694035/)

mierdatuti 12-31-2008 05:31 AM

Assign a value
 
Hi,

I have a code html:
Code:

......
......
</script><br></center></div></div><div id="cuerpo"><br><font class="ficha_peli_dato">Sinopsis:</font><div class="cajasinopsis">
    <div class="cajasinopsisarriba">
      <div class="cajasinopsisabajo">
          <font class="ficha_peli">Las dos hermosas hermanas Bolena, Anne (Natalie Portman) y Mary (Scarlett Johansson), presas de l
as ciegas ambiciones de su familia, compiten por el amor del apuesto y apasionado rey Enrique VIII (Eric Bana). Aunque ambas compart
en el lecho del Rey, solo una sera reina durante un breve y turbulento momento que acabara bajo la espada del verdugo
.</font>
      </div>
    </div>
</div></div></div><div id="separador"></div><div id="contenido"><div id="cuerpo2"><br><font class="ficha_peli_dato">Imagenes:</font>
        <div id="cartel"><center><a href=http://www.elseptimoarte.net/imagenes/peliculas/2921.jpg title="Imagen de Las hermanas Bole
na (The Other Boleyn Girl)" class="thickbox" rel="gallery-plants"><img src=http://www.elseptimoarte.net/imagenes/peliculas/150/2921.
jpg alt="Foto de Las hermanas Bolena (The Other Boleyn Girl)" border="0"></a></center></div><div id="cartel">

I would like to asign to variable the value in bold. The problem is that the field "<font class="ficha_peli">" is repeated. The field that it's not repeated is "cajasinopsisabajo".

How could I do this in bash?

Many thanks and sorry for my english!

kscott121 12-31-2008 08:44 AM

We can't (usually) just 'write' your script for you....

Give it a try and submit what your script isn't quite doing correctly and folks will help you correct them.

Happy New Year!!

reddazz 12-31-2008 08:55 AM

When submitting a portion of code to the forum, can you please enclose it in code tags [code*] [/code*] (without the *).

mierdatuti 12-31-2008 10:23 AM

Quote:

Originally Posted by reddazz (Post 3392614)
When submitting a portion of code to the forum, can you please enclose it in code tags [code*] [/code*] (without the *).

Sorry I've modificed the post.

Well, I do it, it's a solution tiresome but it works. I would like to do with sed but I couln't be capable. :-(

I do:

awk '/cajasinopsisabajo/{where=NR;print}NR==where+1 && where!=0 {print}' curl 1>h 2>/dev/null
grep -v div h > h2
nawk '{sub(".*\">","")} {print}' h2 > h3
nawk '{sub("<\/.*","")} {print}' h3 > sinopsis

Thanks!

Kenhelm 12-31-2008 01:50 PM

Using GNU sed
Code:

t1='<div class="cajasinopsisabajo">'
t2='<font class="ficha_peli">'
t3='<\/font>'
t4='<\/div>'
sed -n "/$t1/,/$t4/{/$t2/{:a s/$t3.*//;tb;N;ba;:b s/.*$t2//p}}" file

In your example data t2 and t3 are on separate lines but they might be on the same line if they had shorter text between them.
This has made the sed expression more complicated.
/$t1/,/$t4/ {/$t2/ addresses a line containing t2 which is in the range /$t1/,/$t4/.
Lines are appended to the pattern space by N until t3 is found and deleted along with anything after it.
Then t2 and anything before it are deleted and the pattern space printed.
ba means 'goto label :a' (this creates a loop).
tb means 'goto label :b if there's been a successful substitution in the s command' (this breaks out of the loop).


All times are GMT -5. The time now is 10:12 AM.