LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 12-31-2008, 05:31 AM   #1
mierdatuti
Member
 
Registered: Aug 2008
Posts: 61

Rep: Reputation: 15
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!

Last edited by mierdatuti; 12-31-2008 at 10:19 AM. Reason: CORRECTION
 
Old 12-31-2008, 08:44 AM   #2
kscott121
Member
 
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
reddazz
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
mierdatuti
Member
 
Registered: Aug 2008
Posts: 61

Original Poster
Rep: Reputation: 15
Quote:
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

Thanks!
 
Old 12-31-2008, 01:50 PM   #5
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 356

Rep: Reputation: 166Reputation: 166
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).

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


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 PM.

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