Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-31-2008, 05:31 AM   #1
Registered: Aug 2008
Posts: 64

Rep: Reputation: 15
Assign a value


I have a code html:
</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 id="separador"></div><div id="contenido"><div id="cuerpo2"><br><font class="ficha_peli_dato">Imagenes:</font>
        <div id="cartel"><center><a href= title="Imagen de Las hermanas Bole
na (The Other Boleyn Girl)" class="thickbox" rel="gallery-plants"><img src=
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!

Last edited by mierdatuti; 12-31-2008 at 10:19 AM. Reason: CORRECTION
Old 12-31-2008, 08:44 AM   #2
Registered: Jul 2003
Location: NC
Distribution: Fedora,Mepis,Debian
Posts: 84

Rep: Reputation: 15
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!!
Old 12-31-2008, 08:55 AM   #3
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
When submitting a portion of code to the forum, can you please enclose it in code tags [code*] [/code*] (without the *).
Old 12-31-2008, 10:23 AM   #4
Registered: Aug 2008
Posts: 64

Original Poster
Rep: Reputation: 15
Originally Posted by reddazz View Post
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

Old 12-31-2008, 01:50 PM   #5
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
Using GNU sed
t1='<div class="cajasinopsisabajo">'
t2='<font class="ficha_peli">'
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).

Last edited by Kenhelm; 12-31-2008 at 02:48 PM. Reason: Clarification


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to assign a static IP freak_vss Linux - Networking 4 08-26-2008 08:03 PM
commands to assign IP yusufs Linux - Newbie 1 06-17-2008 05:17 PM
Manual Ip Assign? fuelinjection Linux - Networking 8 11-28-2003 03:37 AM
How to assign a driver... whitmell Linux - Newbie 4 09-16-2003 07:36 AM
How to assign shortcouts? Xiangbuilder Linux - Newbie 2 08-31-2003 07:46 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration