Thread View: es.comp.os.linux.programacion
12 messages
12 total messages
Started by ABSOLUT
Thu, 01 Jan 2009 19:08
Problemas con sed
Author: ABSOLUT
Date: Thu, 01 Jan 2009 19:08
Date: Thu, 01 Jan 2009 19:08
45 lines
3345 bytes
3345 bytes
Hola a todos, Tengo un fichero de texto con un codigo html todo en una misma linea, os pongo un trozo: .............. <div align="left"></div><table border=0 cellpadding=0 cellspacing=0 width=100% class="t bb"><tr><td nowrap></td>< td align=right nowrap><font size=-1>Resultados <b>1</b> - <b>10</b> de <b>hermas bolena</b> (<b>0.07</b> segundo s) </font></td></tr></table><div id=res><p><font color="#cc0000" class=p>Quiz�s quiso decir: </font><a href= "/custom?hl=es&client=google-coop-np&cof=FORID:11%3BAH:left %3BL:http://www.google.com/coop/intl/es/images /custom_search_sm.gif%3BLH:65%3BLP:1%3BBGC:%23f7f8fc%3BVLC: %23663399%3BGALT:%23009900%3BDIV:%23a7a6a6%3B&ad=w 9&cx=003284578463992023034:lraatm7pya0&adkw=AELymgWpiI3ffTqEb_xlTxgtMMwdNRsUtwR7V- b8kzLEoC-I4U1M5pO7feaDi -o3sTOFC2M4zgBSn2HFxiCVWbgmUplbWBdDG2yFNUIDeJ5AKwTu- G5c9T4&oe=ISO-8859-1&sa=X&oi=spell&resnum=0&a mp;ct=result&cd=1&q=hermanas+bolena&spell=1" class=p><b><i>hermanas</i></b> bolena</a> <br ><div><ol style="margin:0;padding:0;list-style:none"><table align=right><tr><td align=left><a href="http://www.go ogle.com/coop/cse/?hl=es" target=_top><img src="/images/ poweredby_transparent/poweredby_FFFFFF.gif" alt=Google bo rder=0></a><br><span style="font-size:9px;font- weight:bolder;color:#000000"> B�squeda personalizada</span></ td></tr></table><li><div class=g><h2 class=r><a href="http:// www.elseptimoarte.net/peliculas/the-other-boleyn-gir l-1121.html" target=_top class=l>Las <em>hermanas Bolena</em> (2008) - El S�ptimo Arte</a></h2><table border=0 ce llpadding=0 cellspacing=0><tr><td class="j"><div class=std>16 Nov 2007 <b>...</b> Sinopsis de la pel�cula Las <em...... Quiero sacar unas urls que estan en el fichero y me he dado cuenta que coinciden en un patron. Todas comienzan por <a href="http...... y finalizan con ". Pero no se como hacerlo... lo he intentado con sed pero al estar en una linea no se muy bien como realizarlo Alguna ayduda? Gracias
Re: Problemas con sed
Author: Ignacio Arenaza
Date: Fri, 02 Jan 2009 00:27
Date: Fri, 02 Jan 2009 00:27
39 lines
2327 bytes
2327 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
ABSOLUT <davidtuti@gmail.com> writes:
> Tengo un fichero de texto con un codigo html todo en una misma linea,
> os pongo un trozo:
>
> ..............
>
> Quiero sacar unas urls que estan en el fichero y me he dado cuenta que
> coinciden en un patron. Todas comienzan por <a href="http...... y
> finalizan con ". Pero no se como hacerlo... lo he intentado con sed
> pero al estar en una linea no se muy bien como realizarlo
Con sed no he sido capaz de sacar nada en limpio. Con Perl es m�s
manejable. Con algo como lo siguiente consigo sacar cosas bastante
l�mpias (aunque presupone que no aparecen comillas dobles en las URLs,
lo cual puede no ser cierto):
perl -ne '@urls = m/<a href= *"([^"]*?)"/go; foreach $i (@urls) { print $i . "-----\n" }' < fichero
Deber�a ir todo en una l�nea. Si llega partido es por culpa del gestor
de correo :-)
Saludos. I�aki.
- --
Mondragon University
GPG Key available at public keyservers
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Processed by Mailcrypt and GPG
iD8DBQFJXV+CRgC43oKhB3QRAnPrAJ0RFBcSJ69WmrqxX97B0ZABsFiiggCfYBAX
pwUUgaD8ksXRaOu/LL/doYM=
=t/Yu
-----END PGP SIGNATURE-----
Re: Problemas con sed
Author: Ignacio Arenaza
Date: Fri, 02 Jan 2009 00:29
Date: Fri, 02 Jan 2009 00:29
26 lines
1918 bytes
1918 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ignacio Arenaza <iarenaza@eb2ebu.ampr.org> writes:
> perl -ne '@urls = m/<a href= *"([^"]*?)"/go; foreach $i (@urls) { print $i . "-----\n" }' < fichero
Ups! Se me ha olvidado borrar el marcador ('-----') que he usado para
las pruebas intermedias. Deber�a ser:
> perl -ne '@urls = m/<a href= *"([^"]*?)"/go; foreach $i (@urls) { print $i, "\n" }' < fichero
Saludos. I�aki.
- --
Mondragon University
GPG Key available at public keyservers
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Processed by Mailcrypt and GPG
iD8DBQFJXV/YRgC43oKhB3QRAup+AJ409Qx0OR9SRImaHtNsYWp6iJ0fXwCg20aX
gkg+XVTL8GPbMB/zdR+Thk4=
=g6s/
-----END PGP SIGNATURE-----
Re: Problemas con sed
Author: ABSOLUT
Date: Fri, 02 Jan 2009 08:36
Date: Fri, 02 Jan 2009 08:36
33 lines
2286 bytes
2286 bytes
On 2 ene, 01:29, Ignacio Arenaza <iaren...@eb2ebu.ampr.org> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Ignacio Arenaza <iaren...@eb2ebu.ampr.org> writes:
> > perl -ne '@urls = m/<a href= *"([^"]*?)"/go; foreach $i (@urls) { print $i . "-----\n" }' < fichero
>
> Ups! Se me ha olvidado borrar el marcador ('-----') que he usado para
> las pruebas intermedias. Debería ser:
>
> > perl -ne '@urls = m/<a href= *"([^"]*?)"/go; foreach $i (@urls) { print $i, "\n" }' < fichero
>
> Saludos. Iñaki.
>
> - --
> Mondragon University
>
> GPG Key available at public keyservers
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Processed by Mailcrypt and GPG
>
> iD8DBQFJXV/YRgC43oKhB3QRAup+AJ409Qx0OR9SRImaHtNsYWp6iJ0fXwCg20aX
> gkg+XVTL8GPbMB/zdR+Thk4=
> =g6s/
> -----END PGP SIGNATURE-----
Muchas gracias a todos, pero alguien sabe hacer esto con el comando
sed???
Gracias
Re: Problemas con sed
Author: Jesús Carrete Montaña
Date: Fri, 02 Jan 2009 14:25
Date: Fri, 02 Jan 2009 14:25
12 lines
1845 bytes
1845 bytes
> Muchas gracias a todos, pero alguien sabe hacer esto con el comando > sed??? > > Gracias A ver si te vale as�: he usado un bucle en el que cada vez que encuentro una URL la borro del flujo de entrada tras sacarla por pantalla, para que despu�s encuentre la siguiente. As� no dependo de que haya una por l�nea. sed -n ':repetir;h;s/.*<a href="\(http[^"]*\)".*$/\1/p;g;s/\(.*\)<a href="[^"]*".*$/\1/;t repetir' Ojo: todo el comando anterior ha de ir en la misma l�nea, sobra decir... Un saludo a todos.
Re: Problemas con sed
Author: Jesús Carrete Montaña
Date: Fri, 02 Jan 2009 14:27
Date: Fri, 02 Jan 2009 14:27
16 lines
1965 bytes
1965 bytes
Jes�s Carrete Monta�a wrote: > sed -n ':repetir;h;s/.*<a href="\(http[^"]*\)".*$/\1/p;g;s/\(.*\)<a > href="[^"]*".*$/\1/;t repetir' > > Ojo: todo el comando anterior ha de ir en la misma l�nea, sobra decir... > > Un saludo a todos. Perd�n, se me olvid� comprobar que la URL empiece por http antes de borrarla: sed -n ':repetir;h;s/.*<a href="\(http[^"]*\)".*$/\1/p;g;s/\(.*\)<a href="http[^"]*".*$/\1/;t repetir' < html.html Aprovecho para contar que si los href pueden ir en may�sculas o mezclados har�a falta otro comando de sustituci�n (trivial) antes. Un saludo.
Re: Problemas con sed
Author: ABSOLUT
Date: Fri, 02 Jan 2009 20:18
Date: Fri, 02 Jan 2009 20:18
24 lines
2304 bytes
2304 bytes
On 2 ene, 15:27, Jesús Carrete Montaña <kuant...@escomposlinux.org> wrote: > Jesús Carrete Montaña wrote: > > sed -n ':repetir;h;s/.*<a href="\(http[^"]*\)".*$/\1/p;g;s/\(.*\)<a > > href="[^"]*".*$/\1/;t repetir' > > > Ojo: todo el comando anterior ha de ir en la misma línea, sobra decir... > > > Un saludo a todos. > > Perdón, se me olvidó comprobar que la URL empiece por http antes de borrarla: > > sed -n ':repetir;h;s/.*<a href="\(http[^"]*\)".*$/\1/p;g;s/\(.*\)<a href="http[^"]*".*$/\1/;t repetir' < html.html > > Aprovecho para contar que si los href pueden ir en mayúsculas o mezclados haría falta otro comando de sustitución (trivial) antes. > > Un saludo. Muchas gracias, ahora no tengo tiempo pero mañana lo prueba. Gracias,
Re: Problemas con sed
Author: Ignacio Arenaza
Date: Sat, 03 Jan 2009 16:30
Date: Sat, 03 Jan 2009 16:30
35 lines
2610 bytes
2610 bytes
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jes�s Carrete Monta�a <kuantiko@escomposlinux.org> writes: > Perd�n, se me olvid� comprobar que la URL empiece por http antes de borrarla: > > sed -n ':repetir;h;s/.*<a href="\(http[^"]*\)".*$/\1/p;g;s/\(.*\)<a href="http[^"]*".*$/\1/;t repetir' < html.html Peque�o detalle adicional: las URLs de un href no tienen porque ser del tipo http:/..., puede ser URLs relativas. Es decir, habr�a que quitar las referencias a 'http' de los patrones de busqueda. sed -n ':repetir;h;s/.*<a href="\([^"]*\)".*$/\1/p;g;s/\(.*\)<a href="[^"]*".*$/\1/;t repetir' < html.html Si ademas puede haber espacios en blando antes y depues de los '=' y las '"' (que lo puede haber), la cosa se puede complicar un pel�n m�s. Por cierto Kuantiko, ���cuantos a�os sin leerte!!! Supongo que ya no tendr�s la pinta de la foto de la p�gina de habituales de ecol :-) Saludos. I�aki. - -- Mondragon University GPG Key available at public keyservers -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Processed by Mailcrypt and GPG iD8DBQFJX5KlRgC43oKhB3QRAoofAKCjK5GWJ28MmOh3rziPGmb+SD53JQCgsRqu I3ZkuGzczC4zM5T/WDd/ieA= =9o1i -----END PGP SIGNATURE-----
Re: Problemas con sed
Author: Jesús Carrete Montaña
Date: Sat, 03 Jan 2009 16:55
Date: Sat, 03 Jan 2009 16:55
27 lines
3293 bytes
3293 bytes
Ignacio Arenaza wrote: > Peque�o detalle adicional: las URLs de un href no tienen porque ser > del tipo http:/..., puede ser URLs relativas. Es decir, habr�a que > quitar las referencias a 'http' de los patrones de busqueda. No te falta raz�n; yo simplemente estaba implementando lo especificado por ABSOLUT en el mensaje original de este hilo > > sed -n ':repetir;h;s/.*<a href="\([^"]*\)".*$/\1/p;g;s/\(.*\)<a > href="[^"]*".*$/\1/;t repetir' < html.html > > Si ademas puede haber espacios en blando antes y depues de los '=' y > las '"' (que lo puede haber), la cosa se puede complicar un pel�n m�s. En efecto. He estado buscando en google si hab�a alguna soluci�n un poco m�s profesional ya implementada y he encontrado el siguiente script: http://sed.sf.net/grabbag/scripts/list_urls.sed Usa la misma idea del bucle que yo, pero con cierta preparaci�n previa para tener en cuenta may�suculas/min�sculas, espacios y dem�s. Est� bien, pero ya excede los l�mites de los "one-liner" cl�sicos y de necesitar tanto yo me ir�a m�s bien a las bibliotecas de Python o Perl que implementan el est�ndar m�s a fondo. Lo m�o es una soluci�n chapucera para salir de un apuro :-) > Por cierto Kuantiko, ���cuantos a�os sin leerte!!! Supongo que ya no > tendr�s la pinta de la foto de la p�gina de habituales de ecol :-) Hombre, si le pones barba rubia a la foto con el Tux Paint casi sacas mi aspecto actual ;-). He mirado la p�gina y me ha tra�do buenos recuerdos (tampoco he cambiado tanto). Afortunadamente he cumplido ya con alguna de las ambiciones all� se�aladas, aunque no la de acabar con el spam... sigo aqu�, acechando los grupos desde las sombras. Un saludo.
Re: Problemas con sed
Author: ABSOLUT
Date: Mon, 05 Jan 2009 09:19
Date: Mon, 05 Jan 2009 09:19
59 lines
4504 bytes
4504 bytes
Muchas gracias por vuestra ayuda pero me asalta otra duda que como os
veo profesionales del sed lo mismo me podéis solucionar.
Si tengo un texto html como mas abajo os pongo y quiero sacar lo de
las X de esta cadena:
....window.open('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').....
Yo hago:
sed "s/.*window\.open('\([^']*\)'.*$/\1/g" fichero.html
Pero no me lo hace :-(
Sabeis porque puede ser.?
<tr><td class=lista align=left width=100%><table border=0
cellspacing=0 cellpadding=0 align=left width=90%><tr><td width=60
style="b
ackground-image: url(./style/base/line_a.gif); background-repeat: no-
repeat; background-position:top right; width=60px; height:4px;"
></td><td width=75% style="background-image:url(./style/base/line_b.gif); background-repeat: repeat-x; height:4px;"></td><td width=6
0 style="background-image: url(./style/base/line_c.gif); background-
repeat: no-repeat; height:4px;"></td></tr></table></td></tr>
<tr><td class=lista align=left><table align=left border=0
cellspacing=0 cellpadding=0 width=70%><tr><td class=lista align=left>
<b>Options: </b></td>
<td class=lista align=left title="Bajar: Austin Powers -
Misterioso agente internacional [DVDRip][DIVX][mp3][Es][1997] "><table
border=0 cellspacing=0 cellpadding=0 align=left onClick="window.open
('download.php?id=7f5f11d0c4a8ccebe59342e29de2c8cf7e5096e3&f=Au
stin+Powers+-+Misterioso+agente+internacional+%5BDVDRip%5D%5BDIVX%5D
%5Bmp3%5D%5BEs%5D%5B1997%5D+.torrent','_self')" style="cursor:po
inter; cursor:hand;"><tr><td style="background-image: url(images/
download.gif); background-repeat: no-repeat; width:17px; height:17p
x;" align=center></td><td> Descargar</td></tr></table></td>
<td class=lista align=left title="Details for: Austin Powers -
Misterioso agente internacional [DVDRip][DIVX][mp3][Es][1997] ">
<table border=0 cellspacing=0 cellpadding=0 align=left
onClick="javascript:popdetails('details.php?
id=7f5f11d0c4a8ccebe59342e29de2c8
cf7e5096e3&hit=1');" style="cursor:pointer; cursor:hand;"><tr><td
style="background-image: url(images/torrent_name.gif); backgro
und-repeat: no-repeat; width:17px; height:17px;" align=center></
td><td> Detalles</td></tr></table></td>
<td class=lista align=left
title="Add to WishList: Austin Powers - Misterioso
agente internacional [DVDRip][DIVX][mp3
][Es][1997] "><table border=0 cellspacing=0 cellpadding=0 align=left
onClick="window.open('wishlist.php?do=add&torrent_id=7f5f11
d0c4a8ccebe59342e29de2c8cf7e5096e3','_self')" style="cursor:pointer;
cursor:hand;"><tr><td style="background-image: url(images/wishl
ist.gif); background-repeat: no-repeat; width:17px; height:17px;"
align=center></td><td> Aqadir a tu lista de espera</td></tr><
/table></td>
Muchas gracias y un saludo,
Re: Problemas con sed
Author: Jesús Carrete Montaña
Date: Tue, 06 Jan 2009 10:27
Date: Tue, 06 Jan 2009 10:27
14 lines
1974 bytes
1974 bytes
ABSOLUT wrote:
> Yo hago:
>
> sed "s/.*window\.open('\([^']*\)'.*$/\1/g" fichero.html
Lo acabo de probar con el html que pones en tu mensaje (pero ojo, todo en la misma l�nea, como dec�as en tu mensaje original) y a mi me funciona.
sousaw@quark:/tmp$ sed "s/.*window\.open('\([^']*\)'.*$/\1/g" html.html
wishlist.php?do=add&torrent_id=7f5f11d0c4a8ccebe59342e29de2c8cf7e5096e3
�Qu� te sale a t�?
Un saludo.
Re: Problemas con sed
Author: ABSOLUT
Date: Tue, 06 Jan 2009 13:33
Date: Tue, 06 Jan 2009 13:33
75 lines
4727 bytes
4727 bytes
On 6 ene, 11:27, Jesús Carrete Montaña <kuant...@escomposlinux.org>
wrote:
> ABSOLUT wrote:
> > Yo hago:
>
> > sed "s/.*window\.open('\([^']*\)'.*$/\1/g" fichero.html
>
> Lo acabo de probar con el html que pones en tu mensaje (pero ojo, todo en la misma línea, como decías en tu mensaje original) y a mi me funciona.
>
> sousaw@quark:/tmp$ sed "s/.*window\.open('\([^']*\)'.*$/\1/g" html.html
> wishlist.php?do=add&torrent_id=7f5f11d0c4a8ccebe59342e29de2c8cf7e5096e3
>
> ¿Qué te sale a tí?
>
> Un saludo.
Ya me sale bien, es que esta en otra shell jeje.
Pero tengo otra duda: si tengo esto:
<td class=lista align=left title="Bajar: [Capitulos 1-8] House 5�
Temporada HDTV x264 720p AC3 5.1 Dual + Subs Dual "><table border=0
cellspacing=0 cell
padding=0 align=left onClick="window.open('download.php?
id=6f0fa8a03a424e203471224a92a1565cefd4a5ee&f=%5BCapitulos+1-8%5D+House
+5%AA+Temporada+HDTV+x264+720p
+AC3+5.1+Dual+%2B+Subs+Dual+.torrent','_self')" style="cursor:pointer;
cursor:hand;"><tr><td style="background-image: url(images/
download.gif); background-re
peat: no-repeat; width:17px; height:17px;" align=center></
td><td> Descargar</td></tr></table></td>
<td class=lista align=left title="Bajar: (.XviDG ) Mundial de
Motogp 2008 - Resumen TVE.DVBRip.XviD.Mp3.Castellano"><table border=0
cellspacing=0 cellpa
dding=0 align=left onClick="window.open('download.php?
id=fcff167524fa499cb02ce820ebc6fe39b36538c6&f=%28.XviDG+%29+Mundial+de
+Motogp+2008+-+Resumen+TVE.DVBRip
.XviD.Mp3.Castellano.torrent','_self')" style="cursor:pointer;
cursor:hand;"><tr><td style="background-image: url(images/
download.gif); background-repeat: no
-repeat; width:17px; height:17px;" align=center></
td><td> Descargar</td></tr></table></td>
Y si hago esto:
sed "s/.*nbsp;\([^\"]*\)\".*$/\1/g" fichero me sale:
<td class=lista align=left title="Bajar: [Capitulos 1-8] House 5�
Temporada HDTV x264 720p AC3 5.1 Dual + Subs Dual "><table border=0
cellspacing=0 cellpadding=0 align=left onClick="window.open
('download.php?id=6f0fa8a03a424e203471224a92a1565cefd4a5ee&f=
%5BCapitulos+1-8%5D+House+5%AA+Temporada+HDTV+x264+720p+AC3+5.1+Dual+
%2B+Subs+Dual+.torrent','_self')" style="cursor:pointer;
cursor:hand;"><tr><td style="background-image: url(images/
download.gif); background-repeat: no-repeat; width:17px; height:17px;"
align=center></td><td> Descargar</td></tr></table></td>
(.XviDG ) Mundial de Motogp 2008 - Resumen
TVE.DVBRip.XviD.Mp3.Castellano
Yo querria que me saliera:
House 5� Temporada HDTV x264 720p AC3 5.1 Dual + Subs Dual
(.XviDG ) Mundial de Motogp 2008 - Resumen
TVE.DVBRip.XviD.Mp3.Castellano
No entiendo porque con esa sentencia no me sale lo que yo quiero ya
que las 2 lineas cumplen el mismo patron. Alguna ayuda??
Gracias
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads