<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Smultron POTENCIA !! &#187; Resultados de la búsqueda  &#187;  +2009+12+page+3</title>
	<atom:link href="http://smultron.es/search/+2009+12+page+3/feed/rss2/" rel="self" type="application/rss+xml" />
	<link>http://smultron.es</link>
	<description>El Blog con Potencia pero sin Control.</description>
	<lastBuildDate>Sat, 11 Feb 2012 18:52:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Descargar Paginas Web Usando PHP &#8211; cURL &#8211; file_get_contents</title>
		<link>http://smultron.es/2011/02/descargar-paginas-web-usando-php-curl-file_get_contents/</link>
		<comments>http://smultron.es/2011/02/descargar-paginas-web-usando-php-curl-file_get_contents/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 23:35:37 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programacion]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4943</guid>
		<description><![CDATA[&#160;Via:&#160;www.forosdelweb.com/wiki/PHP:_file_get_contents(),_cURL,_HTTP_Request En ForosDelWeb he encontrado varias maneras de descargar paginas web utilizando PHP. Definiciones file_get_contents() cURL HTTP_Request Introducci&#243;n Hay varias maneras de mostrar un URL remoto en PHP. La elecci&#243;n de un m&#233;todo sobre otro depende de las necesidades de su simplicidad, control y portabilidad. Los tres m&#233;todos que vamos a describir son: Las funciones [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;Via:&nbsp;<a target="_blank" href="http://www.forosdelweb.com/wiki/PHP:_file_get_contents(),_cURL,_HTTP_Request">www.forosdelweb.com/wiki/PHP:_file_get_contents(),_cURL,_HTTP_Request</a></p>
<p>En ForosDelWeb he encontrado varias maneras de descargar paginas web utilizando PHP.</p>
<p><span id="more-4943"></span><br />
<meta charset="utf-8" /><span class="Apple-style-span" style="font-family: sans-serif; font-size: 13px; line-height: 19px; "></p>
<h2 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.6em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(170, 170, 170); font-size: 23px; padding-top: 0.6em; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Definiciones</span></h2>
<ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.forosdelweb.com/w/skins/monobook/bullet.gif); ">
<li style="margin-bottom: 0.3em; "><a href="http://php.net/file_get_contents" class="external text" title="http://php.net/file_get_contents" rel="nofollow" style="text-decoration: none; color: rgb(51, 102, 187); background-image: url(http://www.forosdelweb.com/w/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">file_get_contents()</a></li>
<li style="margin-bottom: 0.3em; "><a href="http://php.net/manual/en/intro.curl.php" class="external text" title="http://php.net/manual/en/intro.curl.php" rel="nofollow" style="text-decoration: none; color: rgb(51, 102, 187); background-image: url(http://www.forosdelweb.com/w/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">cURL</a></li>
<li style="margin-bottom: 0.3em; "><a href="http://pear.php.net/manual/en/package.http.http-request.php" class="external text" title="http://pear.php.net/manual/en/package.http.http-request.php" rel="nofollow" style="text-decoration: none; color: rgb(51, 102, 187); background-image: url(http://www.forosdelweb.com/w/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">HTTP_Request</a></li>
</ul>
<p><a name="Introducci.C3.B3n" id="Introducci.C3.B3n" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h2 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.6em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(170, 170, 170); font-size: 23px; padding-top: 0.6em; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Introducci&oacute;n</span></h2>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Hay varias maneras de mostrar un URL remoto en PHP. La elecci&oacute;n de un m&eacute;todo sobre otro depende de las necesidades de su simplicidad, control y portabilidad. Los tres m&eacute;todos que vamos a describir son:</p>
<ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.forosdelweb.com/w/skins/monobook/bullet.gif); ">
<li style="margin-bottom: 0.3em; ">Las funciones estandares de &quot;<b>filesystem</b>&quot;</li>
<li style="margin-bottom: 0.3em; ">La extensi&oacute;n&nbsp;<b>cURL</b></li>
<li style="margin-bottom: 0.3em; ">La clase de PEAR&nbsp;<b>HTTP_Request</b>.</li>
</ul>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Estos tres m&eacute;todos pueden generalmente hacer todo lo que necesita y por lo menos uno de ellos deben estar disponibles, sea cual sea su configuraci&oacute;n del servidor o capacidad de instalar las extensiones personalizadas. Otras formas de recuperar las URL remotas incluye la extesi&oacute;n pecl_http (<a href="http://pecl.php.net/package/pecl_http" class="external free" title="http://pecl.php.net/package/pecl_http" rel="nofollow" style="text-decoration: none; color: rgb(51, 102, 187); background-image: url(http://www.forosdelweb.com/w/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">http://pecl.php.net/package/pecl_http</a>), que, aunque todav&iacute;a en desarrollo, ofrece algunas caracter&iacute;sticas prometedoras, y utilizando el&nbsp;<b>fsockopen()</b>&nbsp;para abrir un z&oacute;calo sobre el que env&iacute;a una petici&oacute;n HTTP que lo construye pieza por pieza.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">El uso de las funciones estandares de &quot;<b>filesystem</b>&quot; como la funci&oacute;n<b>file_get_contents()</b>&nbsp;es simple y conveniente. Sigue automaticamente las redirecciones, as&iacute; que si utiliza esta funci&oacute;n para recuperar el directorio<i><b>http://www.example.com/persona/</b></i>&nbsp;y el servidor le redirecciona a<i><b>http://www.example.com/people/</b></i>, obtendr&aacute; el contenido de la p&aacute;gina de &iacute;ndice de directorio, no un mensaje que le diga que la URL ha cambiado de direcci&oacute;n. El inconveniente de este m&eacute;todo es que requiere la directiva de configuraci&oacute;n<b>allow_url_fopen</b>&nbsp;a estar activado.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">La extensi&oacute;n&nbsp;<b>CURL</b>&nbsp;es una poderosa herramienta. Se basa en el popular&nbsp;<a href="http://curl.haxx.se/" class="external text" title="http://curl.haxx.se/" rel="nofollow" style="text-decoration: none; color: rgb(51, 102, 187); background-image: url(http://www.forosdelweb.com/w/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">libcurl</a>&nbsp;para proporcionar un r&aacute;pido, configurable mecanismo para el manejo de una amplia variedad de peticiones de red. Si esta extensi&oacute;n est&aacute; disponible en su servidor, le recomendamos que la utilice.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Si se desactiva&nbsp;<b>allow_url_fopen</b>&nbsp;y&nbsp;<b>cURL</b>&nbsp;no est&aacute; disponible, el m&oacute;dulo PEAR<b>HTTP_Request</b>&nbsp;salva el d&iacute;a. Al igual que todos los m&oacute;dulos de PEAR, es puro PHP, por lo que si puede guardar un archivo PHP en su servidor, puede utilizarlo.<b>HTTP_Request</b>&nbsp;soporta casi cualquier cosa que te gustar&iacute;a hacer cuando se solicite una URL remota, incluyendo la modificaci&oacute;n de cabeceras de petici&oacute;n y el cuerpo, utilizando un m&eacute;todo arbitrario, respuesta y recuperaci&oacute;n de los encabezados. Para mas informacion sobre como instalar los modulo de PEAR puedes ir a<a href="http://pear.php.net/manual/en/installation.getting.php" class="external free" title="http://pear.php.net/manual/en/installation.getting.php" rel="nofollow" style="text-decoration: none; color: rgb(51, 102, 187); background-image: url(http://www.forosdelweb.com/w/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">http://pear.php.net/manual/en/installation.getting.php</a></p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Para recibir informaci&oacute;n de URL seguras, solo escribe https en vez de http. Siempre y cuando en PHP haya sido construido en una libreria SSL, tal como&nbsp;<i>OpenSSL</i>. Todas las funciones que pueden recibir informaci&oacute;n de URL regulares pueden recibir informaci&oacute;n de URL seguras. Verifica la secci&oacute;n de&nbsp;<i>OpenSSL</i>&nbsp;en la salida de&nbsp;<b>phpinfo()</b>&nbsp;para ver si tu configuraci&oacute;n de php tiene soporte de SSL.</p>
<p><a name="Ejemplos" id="Ejemplos" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h2 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.6em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(170, 170, 170); font-size: 23px; padding-top: 0.6em; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Ejemplos</span></h2>
<p><a name="Obteniendo_una_URL" id="Obteniendo_una_URL" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Obteniendo una URL</span></h3>
<p><a name="file_get_contents.28.29" id="file_get_contents.28.29" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents()</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/algo.txt'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="cURL" id="cURL" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$c</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/algo.txt'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_close<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="HTTP_Request" id="HTTP_Request" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">HTTP_Request</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="kw1" style="color: rgb(177, 177, 0); ">require_once</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'HTTP/Request.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">new</span> HTTP_Request<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/algo.txt'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">sendRequest</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">getResponseBody</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Mostrar_una_p.C3.A1gina_protegida" id="Mostrar_una_p.C3.A1gina_protegida" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Mostrar una p&aacute;gina protegida</span></h3>
<p><a name="file_get_contents.28.29_2" id="file_get_contents.28.29_2" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents()</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://FDW:PASS@www.example.com/proyecto.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="cURL_2" id="cURL_2" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$c</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/proyecto.php'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_USERPWD<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'FDW:PASS'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_close<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="HTTP_Request_2" id="HTTP_Request_2" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">HTTP_Request</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">new</span> HTTP_Request<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/proyecto.php'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">setBasicAuth</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'FDW'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span><span class="st_h" style="color: rgb(0, 0, 255); ">'PASS'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">sendRequest</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">getResponseBody</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Usar_el_metodo_de_POST" id="Usar_el_metodo_de_POST" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Usar el metodo de POST</span></h3>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Enviar por el m&eacute;todo de POST requiere de manejo especial en cada argumento. Con el m&eacute;todo de GET, estos argumentos est&aacute;n en la cadena de consulta, pero en un POST van en la solicitud cuerpo. Adem&aacute;s, la solicitud necesita una cabecera Content-Length que le dice al servidor el tama&ntilde;o del contenido a esperar en la solicitud cuerpo.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Mostrar una direcci&oacute;n URL con el m&eacute;todo de POST en vez del metdo de GET es bien &uacute;til cuando la cadena es muy larga, m&aacute;s de 200 caracteres aproximadamente. La especificaci&oacute;n de HTTP 1.1 en el&nbsp;<a href="http://tools.ietf.org/html/rfc2616" class="external text" title="http://tools.ietf.org/html/rfc2616" rel="nofollow" style="text-decoration: none; color: rgb(51, 102, 187); background-image: url(http://www.forosdelweb.com/w/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">RFC 2616</a>&nbsp;no impone una longitud m&aacute;xima en las URL, por lo que el comportamiento var&iacute;a entre las diferentes web y servidores proxy. Si al mostrar las URL con GET y recibes resultados inesperados o resultados con el c&oacute;digo de estado 414 ( &quot;<i><b>Request-URI Too Long</b></i>&quot;), convierte la solicitud al m&eacute;todo de POST.</p>
<p><a name="file_get_contents.28.29_3" id="file_get_contents.28.29_3" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents()</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/submit.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$body</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'FDW=programacion&amp;PHP=f18'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$options</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'method'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'POST'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'content'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="re0" style="color: rgb(0, 0, 136); ">$body</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$context</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/stream_context_create" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">stream_context_create</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="re0" style="color: rgb(0, 0, 136); ">$options</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">false</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="re0" style="color: rgb(0, 0, 136); ">$context</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="cURL_3" id="cURL_3" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/submit.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$body</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'FDW=programacion&amp;PHP=f18'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$c</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_POST<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_POSTFIELDS<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="re0" style="color: rgb(0, 0, 136); ">$body</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_close<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="HTTP_Request_3" id="HTTP_Request_3" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">HTTP_Request</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="kw1" style="color: rgb(177, 177, 0); ">require</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'HTTP/Request.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/submit.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">new</span> HTTP_Request<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">setMethod</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span>HTTP_REQUEST_METHOD_POST<span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">addPostData</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'FDW'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span><span class="st_h" style="color: rgb(0, 0, 255); ">'programacion'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">addPostData</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'PHP'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span><span class="st_h" style="color: rgb(0, 0, 255); ">'f18'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">sendRequest</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">getResponseBody</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Enviar_cookies" id="Enviar_cookies" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Enviar cookies</span></h3>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Las cookies se env&iacute;an al servidor en el encabezado de solicitud de cookies. La extensi&oacute;n cURL tiene una opci&oacute;n espec&iacute;fica en cookies, pero con HTTP_Request, tienes que agregar el encabezado de cookies al igual que con otras cabeceras de petici&oacute;n. Los valores de Cookie m&uacute;ltiples se env&iacute;an en una lista delimitada por coma. En los ejemplos vamos a enviar dos cookies: una con el nombre de user y con el valor FDW y otra con el nombre de actividad y con el valor de programacion.</p>
<p><a name="file_get_contents.28.29_4" id="file_get_contents.28.29_4" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents()</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$options</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span>
    <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span>
        <span class="st_h" style="color: rgb(0, 0, 255); ">'method'</span>  <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'GET'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span>
        <span class="st_h" style="color: rgb(0, 0, 255); ">'header'</span>  <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'Content-type: text/plain;charset=UTF-8\r\n'</span><span class="sy0" style="color: rgb(51, 153, 51); ">.</span>
        <span class="st_h" style="color: rgb(0, 0, 255); ">'Referer: http://www.forosdelweb.com\r\n'</span><span class="sy0" style="color: rgb(51, 153, 51); ">.</span>
        <span class="st_h" style="color: rgb(0, 0, 255); ">'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6\r\n'</span><span class="sy0" style="color: rgb(51, 153, 51); ">.</span>
        <span class="st_h" style="color: rgb(0, 0, 255); ">'Cookie: user=FDW; actividad=programacion;\r\n'</span>
    <span class="br0" style="color: rgb(0, 153, 0); ">)</span>
<span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$context</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/stream_context_create" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">stream_context_create</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$options</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/enviar-cookies.php'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">false</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="re0" style="color: rgb(0, 0, 136); ">$context</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="cURL_4" id="cURL_4" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$c</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/enviar-cookies.php'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_COOKIE<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'user=FDW; actividad=programacion'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_close<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="HTTP_Request_4" id="HTTP_Request_4" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">HTTP_Request</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="kw1" style="color: rgb(177, 177, 0); ">require</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'HTTP/Request.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">new</span> HTTP_Request<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/enviar-cookies.php'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">addHeader</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'Cookie'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span><span class="st_h" style="color: rgb(0, 0, 255); ">'user=FDW; actividad=programacion'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">sendRequest</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">getResponseBody</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Seguir_redireccionamientos" id="Seguir_redireccionamientos" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Seguir redireccionamientos</span></h3>
<p><a name="file_get_contents.28.29_5" id="file_get_contents.28.29_5" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents()</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; "><i><b>Nota:</b></i>&nbsp;El&nbsp;<b>file_get_contents()</b>&nbsp;sigue autom&aacute;ticamente las redirecciones (<i>header(&quot;Location: redireccion.php&quot;)</i>).</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/redireccionar.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="cURL_5" id="cURL_5" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$c</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/redireccionar.php'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_FOLLOWLOCATION<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_close<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="HTTP_Client" id="HTTP_Client" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">HTTP_Client</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; "><i><b>Nota:</b></i>&nbsp;<b>HTTP_request</b>&nbsp;no sigue las redirecciones, pero el m&oacute;dulo de PEAR&nbsp;<b>HTTP_Client</b>&nbsp;logra lo que queremos</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/redireccionar.php'</span>;
<span class="kw1" style="color: rgb(177, 177, 0); ">require_once</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'HTTP/Client.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$client</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">new</span> HTTP_Client<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$client</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">get</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="re0" style="color: rgb(0, 0, 136); ">$client</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">currentResponse</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span><span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="st_h" style="color: rgb(0, 0, 255); ">'body'</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="No_seguir_redirecciones" id="No_seguir_redirecciones" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">No seguir redirecciones</span></h3>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Como hemos indicado anteriormente el&nbsp;<b>file_get_contents()</b>&nbsp;sigue autom&aacute;ticamente las redirecciones (<i>header(&quot;Location: redireccion.php&quot;)</i>). A partir de PHP 5.0.0,&nbsp;<b>file_get_contents()</b>&nbsp;y&nbsp;<b>fopen()</b>&nbsp;nos da unas opciones especificas acerca de como obtener el stream. En PHP 5.1.0 y posteriores, una de esas opciones es<b>max_redirects</b>&nbsp;el n&uacute;mero m&aacute;ximo de redirecciones a seguir. Si indicamos el&nbsp;<b>max_redirects</b>&nbsp;a 0 o 1, solo hace una solicitud.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">El&nbsp;<b>max_redirects</b>&nbsp;realmente no indica el n&uacute;mero de redirecciones deben seguirse, pero el n&uacute;mero m&aacute;ximo de solicitudes que deben efectuarse en el momento siguiente a la cadena de redireccionamiento. Es decir, un valor de 1 le dice a PHP que al menos una solicitud debe seguir, y no un redireccionamiento. Un valor de 2 le dice a PHP para que al menos de 2 solicitudes deben seguir y no m&aacute;s de 1 redireccionamiento. Un valor de 0, sin embargo, se comporta como un valor de 1, PHP hace s&oacute;lo 1 solicitud.</p>
<p><a name="file_get_contents.28.29_6" id="file_get_contents.28.29_6" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents()</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/redireccionar.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$options</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'max_redirects'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="nu0" style="color: rgb(204, 102, 204); ">1</span> <span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$context</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/stream_context_create" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">stream_context_create</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="re0" style="color: rgb(0, 0, 136); ">$options</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">false</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="re0" style="color: rgb(0, 0, 136); ">$context</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>; </pre>
<p><a name="cURL_6" id="cURL_6" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; "><i><b>Nota:</b></i>&nbsp;Para no seguir las redirecciones no uses&nbsp;<b>CURLOPT_FOLLOWLOCATION</b></p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$c</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/redireccionar.php'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_close<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="HTTP_Request_5" id="HTTP_Request_5" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">HTTP_Request</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; "><i><b>Nota:</b></i>&nbsp;<b>HTTP_Request</b>&nbsp;no sigue redirecciones</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="kw1" style="color: rgb(177, 177, 0); ">require_once</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'HTTP/Request.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">new</span> HTTP_Request<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/redireccionar.php'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">sendRequest</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">getResponseBody</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Configurar_tiempo_limite" id="Configurar_tiempo_limite" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Configurar tiempo limite</span></h3>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Si quieres obtener una URL remota, pero no quieres esperar demasiado tiempo si el servidor remoto est&aacute; ocupado o lento.</p>
<p><a name="file_get_contents.28.29_7" id="file_get_contents.28.29_7" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents()</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; "><i><b>Nota:</b></i>&nbsp;Estableceremos el tiempo limite a 15 segundos</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<a href="http://www.php.net/ini_set" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">ini_set</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'default_socket_timeout'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="nu0" style="color: rgb(204, 102, 204); ">15</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://slow.example.com/'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;</pre>
<p><a name="cURL_7" id="cURL_7" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; "><i><b>Nota:</b></i>&nbsp;Estableceremos el tiempo limite a 15 segundos</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$c</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://slow.example.com/'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_CONNECTTIMEOUT<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="nu0" style="color: rgb(204, 102, 204); ">15</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_close<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="HTTP_Request_6" id="HTTP_Request_6" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">HTTP_Request</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; "><i><b>Nota:</b></i>&nbsp;Estableceremos el tiempo limite a 15 segundos</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="kw1" style="color: rgb(177, 177, 0); ">require_once</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'HTTP/Request.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$opts</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'timeout'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="nu0" style="color: rgb(204, 102, 204); ">15</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">new</span> HTTP_Request<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://slow.example.com/'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="re0" style="color: rgb(0, 0, 136); ">$opts</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">sendRequest</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Configurar_el_tiempo_de_leer" id="Configurar_el_tiempo_de_leer" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Configurar el tiempo de leer</span></h3>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Si dependes de un servicio remoto, puede estar funcionando y en marcha, pero no estara en condiciones de manejar sus pedidos debido a problemas de red entre tu servidor y el servidor remoto. Limitar la cantidad de tiempo que espera de PHP para conectar a un servidor remoto es una buena idea, si se utilizan datos procedentes de fuentes remotas que sea parte del proceso de construcci&oacute;n de la p&aacute;gina.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Todas las t&eacute;cnicas que describiremos limita la cantidad de tiempo de espera de PHP para conectar a un servidor remoto. Si estas realmente preocupado por las respuestas r&aacute;pidas, adicionalmente configura el l&iacute;mite de cu&aacute;nto tiempo PHP espera recibir los datos de los z&oacute;calos conectados. Para una conexi&oacute;n stream, utilice la funci&oacute;n de [B]stream_set_timeout()[/B]. Para esta funci&oacute;n necesitas abrir un stream con [B]fopen()[/B] y no con [B]file_get_contents()[/B]. En los ejemplo limitaremos el tiempo de leer a 20 segundos.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Aunque el establecimiento de conexi&oacute;n y los tiempos de lectura puede mejorar el rendimiento, tambi&eacute;n puede dar lugar a respuestas ilegibles. La secuencia de comandos puede leer s&oacute;lo una respuesta parcial ante un tiempo de expiraci&oacute;n. Si ha establecido los tiempos, aseg&uacute;rese de validar toda la respuesta que ha recibido. Por otra parte, en situaciones en las que la generaci&oacute;n de la p&aacute;gina r&aacute;pido es fundamental, puedes recuperar los datos externos en un proceso separado y escribir a una memoria cach&eacute; local. De esta forma, sus p&aacute;ginas pueden usar el cach&eacute;, sin temor a l&iacute;mites de tiempo o respuestas parciales.</p>
<p><a name="fopen.28.29" id="fopen.28.29" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">fopen()</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://slow.example.com'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$stream</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/fopen" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">fopen</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'r'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/stream_set_timeout" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">stream_set_timeout</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$stream</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="nu0" style="color: rgb(204, 102, 204); ">20</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> stream_get_contents<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$stream</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/fclose" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">fclose</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$stream</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="cURL_8" id="cURL_8" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$c</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://slow.example.com/'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_CONNECTTIMEOUT<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="nu0" style="color: rgb(204, 102, 204); ">15</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_TIMEOUT<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="nu0" style="color: rgb(204, 102, 204); ">20</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_close<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$c</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p><a name="HTTP_Request_7" id="HTTP_Request_7" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">HTTP_Request</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="kw1" style="color: rgb(177, 177, 0); ">require_once</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'HTTP/Request.php'</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$opts</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'readTimeout'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="nu0" style="color: rgb(204, 102, 204); ">20</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span><span class="nu19" style="color: rgb(128, 0, 128); ">0</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$r</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">new</span> HTTP_Request<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'http://slow.example.com/'</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="re0" style="color: rgb(0, 0, 136); ">$opts</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="re0" style="color: rgb(0, 0, 136); ">$r</span><span class="sy0" style="color: rgb(51, 153, 51); ">-&gt;</span><span class="me1" style="color: rgb(0, 64, 0); ">sendRequest</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<a href="http://www.php.net/echo" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">echo</span></a> <span class="re0" style="color: rgb(0, 0, 136); ">$page</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Otro_m.C3.A9todo_para_incluir_las_variables_y_valores_en_la_consulta" id="Otro_m.C3.A9todo_para_incluir_las_variables_y_valores_en_la_consulta" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Otro m&eacute;todo para incluir las variables y valores en la consulta</span></h3>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">Haciendo uso de&nbsp;<a href="http://www.php.net/http_build_query" class="external text" title="http://www.php.net/http_build_query" rel="nofollow" style="text-decoration: none; color: rgb(51, 102, 187); background-image: url(http://www.forosdelweb.com/w/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">http_build_query()</a>&nbsp;puedes mostrar una p&aacute;gina incluyendo las variables con sus respectivos valores en la consulta. Se acepta una serie de clave/valor en pares y devuelve una &uacute;nica cadena con todo escapado correctamente. Tu eres responsable del s&iacute;mbolo de&nbsp;? en el URL para establecer la consulta.</p>
<p><a name="file_get_contents" id="file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$vars</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="st_h" style="color: rgb(0, 0, 255); ">'FDW'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="nu0" style="color: rgb(204, 102, 204); ">4</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'Programaci&oacute;n'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'PHP &amp; f18'</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$qs</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> http_build_query<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$vars</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/search.php?'</span> <span class="sy0" style="color: rgb(51, 153, 51); ">.</span> <span class="re0" style="color: rgb(0, 0, 136); ">$qs</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;</pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Bajar_archivos" id="Bajar_archivos" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Bajar archivos</span></h3>
<p><a name="file_get_contents_2" id="file_get_contents_2" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">file_get_contents</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st0" style="color: rgb(0, 0, 255); ">&quot;http://www.example.com/zip.zip&quot;</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$g</span><span class="sy0" style="color: rgb(51, 153, 51); ">=</span><a href="http://www.php.net/basename" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">basename</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$content</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/file_get_contents" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">file_get_contents</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
file_put_contents<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$g</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span><span class="re0" style="color: rgb(0, 0, 136); ">$content</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;</pre>
<p><a name="cURL_9" id="cURL_9" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h5 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 17px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h5>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$url</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="st_h" style="color: rgb(0, 0, 255); ">'http://www.example.com/hola.zip'</span>;
&nbsp;
<span class="re0" style="color: rgb(0, 0, 136); ">$g</span><span class="sy0" style="color: rgb(51, 153, 51); ">=</span><a href="http://www.php.net/basename" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">basename</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
&nbsp;
<span class="kw1" style="color: rgb(177, 177, 0); ">if</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="sy0" style="color: rgb(51, 153, 51); ">!</span><a href="http://www.php.net/is_file" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">is_file</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$g</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="br0" style="color: rgb(0, 153, 0); ">{</span>
    <span class="re0" style="color: rgb(0, 0, 136); ">$fp</span><span class="sy0" style="color: rgb(51, 153, 51); ">=</span><a href="http://www.php.net/fopen" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">fopen</span></a> <span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$g</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="st0" style="color: rgb(0, 0, 255); ">&quot;w&quot;</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
&nbsp;
    <span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="sy0" style="color: rgb(51, 153, 51); ">=</span>curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$url</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
    curl_setopt <span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span>CURLOPT_FILE<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="re0" style="color: rgb(0, 0, 136); ">$fp</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
    curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span>CURLOPT_CONNECTTIMEOUT<span class="sy0" style="color: rgb(51, 153, 51); ">,</span><span class="nu0" style="color: rgb(204, 102, 204); ">60</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
    curl_exec <span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
    curl_close <span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
&nbsp;
    <a href="http://www.php.net/fclose" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">fclose</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$fp</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="br0" style="color: rgb(0, 153, 0); ">}</span></pre>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<p><a name="Subir_archivos" id="Subir_archivos" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h3 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 21px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">Subir archivos</span></h3>
<p><a name="cURL_10" id="cURL_10" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "></a></p>
<h4 style="font-family: 'Lucida Grande', Verdana, Arial, sans-serif; letter-spacing: -1px; font-weight: bold; color: rgb(51, 51, 51); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-bottom: 0.17em; border-bottom-width: initial; border-bottom-style: none; border-bottom-color: initial; font-size: 18px; background-position: initial initial; background-repeat: initial initial; "><span class="mw-headline">cURL</span></h4>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; font-size: 1.1em; ">&nbsp;</p>
<pre class="php code" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(47, 111, 171); border-right-color: rgb(47, 111, 171); border-bottom-color: rgb(47, 111, 171); border-left-color: rgb(47, 111, 171); color: black; background-color: rgb(238, 238, 238); line-height: 1.1em; overflow-x: scroll; overflow-y: scroll; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">&lt;?php</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$ch</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_init<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_URL<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="st0" style="color: rgb(0, 0, 255); ">&quot;http://example.com/send_file.php&quot;</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_RETURNTRANSFER<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_POST<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw2" style="color: rgb(0, 0, 0); font-weight: bold; ">true</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="co1" style="color: rgb(102, 102, 102); font-style: italic; ">// lo mismo que &lt;input type=&quot;file&quot; name=&quot;nombre_del_input&quot; /&gt;</span>
<span class="re0" style="color: rgb(0, 0, 136); ">$post</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <a href="http://www.php.net/array" style="text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><span class="kw3" style="color: rgb(153, 0, 0); ">array</span></a><span class="br0" style="color: rgb(0, 153, 0); ">(</span>
    <span class="st0" style="color: rgb(0, 0, 255); ">&quot;nombre_del_input&quot;</span><span class="sy0" style="color: rgb(51, 153, 51); ">=&gt;</span><span class="st0" style="color: rgb(0, 0, 255); ">&quot;@C:/directorio/hacia/el/archivo.jpg&quot;</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span>
<span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
curl_setopt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> CURLOPT_POSTFIELDS<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="re0" style="color: rgb(0, 0, 136); ">$post</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;
<span class="re0" style="color: rgb(0, 0, 136); ">$page</span> <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> curl_exec<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="re0" style="color: rgb(0, 0, 136); ">$ch</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span>;</pre>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2011/02/descargar-paginas-web-usando-php-curl-file_get_contents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Revista</title>
		<link>http://smultron.es/revista-coleopteros/</link>
		<comments>http://smultron.es/revista-coleopteros/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 23:54:11 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://smultron.es/?page_id=4684</guid>
		<description><![CDATA[&#160; Tengo la grata oportunidad de informar que la revista de la Facultad de Inform&#225;tica &#8211; UPM conocida como COLE&#211;PTEROS ha sido adquirida por el Proyecto Smultron. La historia de esta revista se remonta a principios de los a&#241;os 90, y su trayectoria se conmemora hasta finales de 2009, cuando el Proyecto Smultron adopta esta [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://smultron.es/images/titulo-coleopteros.jpg" alt="Revista Coleopteros" /></p>
<p>&nbsp;</p>
<p>Tengo la grata oportunidad de informar que la revista de la <a target="_blank" href="http://www.fi.upm.es"><strong><em>Facultad de Inform&aacute;tica &#8211; UPM</em></strong></a> conocida como <a href="http://coleopteros.smultron.es">COLE&Oacute;PTEROS</a> ha sido adquirida por el<strong> Proyecto Smultron.</strong></p>
<p>La historia de esta revista se remonta a principios de los a&ntilde;os 90, y su trayectoria se conmemora hasta finales de 2009, cuando el Proyecto Smultron adopta esta herramienta como medio de comunicaci&oacute;n y la impulsa para que pase de informar a un grupo reducido de alumnos, a informar a TODO EL MUNDO, compaginando una edici&oacute;n online junto a una edici&oacute;n tradicional.</p>
<p>&nbsp;</p>
<p style="text-align: center;">COLABORADORES | PATROCINADORES | LECTORES | TODO EL MUNDO</p>
<p style="text-align: center;"><span style="font-size: larger;"><a href="javascript:location.href='mailto:'+String.fromCharCode(115,109,117,108,116,114,111,110,112,111,116,101,110,99,105,97,64,103,109,97,105,108,46,99,111,109)+'?subject=Revista%20Smultron%20(Coleopteros)'">CONTACTA !!</a></span></p>
<p>&nbsp;</p>
<p>Aqu&iacute; podeis ver un par de n&uacute;meros de esta exitosa revista.</p>
<p>&nbsp;</p>
<h2>Numeros Anteriores.</h2>
<div style="text-align: center;">
<div style="font-weight: bold;"><a href="http://es.calameo.com/read/00014039476b2f2b70e36">Coleopteros Junio 2009 &#8211; Proyecto Smultron</a></div>
<div style="padding-top: 8px;"><object width="100%" id="00014039476b2f2b70e36" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="http://v.calameo.com/2.0/cmini.swf?bkcode=00014039476b2f2b70e36&amp;langid=es&amp;clickTo=public&amp;clickTarget=_blank&amp;autoFlip=0&amp;showArrows=1&amp;page=1" /><param name="scale" value="noscale" /><param name="loop" value="false" /><param name="salign" value="t" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><embed src="http://v.calameo.com/2.0/cmini.swf" type="application/x-shockwave-flash" scale="noscale" allowscriptaccess="always" loop="false" salign="t" wmode="transparent" style="width: 100%;" flashvars="bkcode=00014039476b2f2b70e36&amp;langid=es&amp;clickTo=public&amp;clickTarget=_blank&amp;autoFlip=0&amp;showArrows=1&amp;page=1"></embed></object></div>
<div style="padding-top: 8px;">&nbsp;</div>
</div>
<p>
&nbsp;</p>
<div style="text-align: center;">
<div style="font-weight: bold;"><a href="http://es.calameo.com/read/0001403941848ead6c5e1">Coleopteros Abril 2008 &#8211; Proyecto Smultron</a></div>
<div style="padding-top: 8px;"><object width="100%" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="0001403941848ead6c5e1"><param value="http://v.calameo.com/2.0/cmini.swf?bkcode=0001403941848ead6c5e1&amp;langid=es&amp;clickTo=public&amp;clickTarget=_blank&amp;autoFlip=0&amp;showArrows=1&amp;page=1" name="movie" /><param value="noscale" name="scale" /><param value="false" name="loop" /><param value="t" name="salign" /><param value="always" name="allowScriptAccess" /><param value="transparent" name="wmode" /><embed flashvars="bkcode=0001403941848ead6c5e1&amp;langid=es&amp;clickTo=public&amp;clickTarget=_blank&amp;autoFlip=0&amp;showArrows=1&amp;page=1" wmode="transparent" salign="t" loop="false" allowscriptaccess="always" scale="noscale" type="application/x-shockwave-flash" src="http://v.calameo.com/2.0/cmini.swf"></embed></object></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/revista-coleopteros/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Maps API &#8211; Personaliza tu mapa</title>
		<link>http://smultron.es/2009/11/google-maps-api-personaliza-tu-mapa/</link>
		<comments>http://smultron.es/2009/11/google-maps-api-personaliza-tu-mapa/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 23:39:35 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[copy&page]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Interesante]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[videotutorial]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4607</guid>
		<description><![CDATA[&#160; Copy&#38;Page: http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web (version Inglesa: http://stiern.com/tutorials/adding-custom-google-maps-to-your-website) En los sitios web de una compa&#241;&#237;a a menudo se utilizan mapas para mostrarle a los clientes d&#243;nde los pueden encontrar. Para esto, Google Maps es excelente. Pero &#191;No ser&#237;a genial a&#241;adir el logo de nuestra compa&#241;&#237;a, los estacionamientos cercanos, las estaciones de trenes, y otros datos alternativos en [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Copy&amp;Page: http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web</p>
<p>(version Inglesa: http://stiern.com/tutorials/adding-custom-google-maps-to-your-website)</p>
<p><span id="more-4607"></span>En los <strong>sitios web</strong> de una compa&ntilde;&iacute;a a menudo se utilizan <strong>mapas</strong> para mostrarle a los<strong> clientes</strong> d&oacute;nde los pueden encontrar. Para esto, <strong>Google Maps</strong> es excelente.</p>
<p>Pero &iquest;No ser&iacute;a genial<strong> a&ntilde;adir el logo</strong> de nuestra compa&ntilde;&iacute;a, los estacionamientos cercanos, las estaciones de trenes,  y otros <strong>datos alternativos</strong> en el mapa para <strong>ayudar</strong> m&aacute;s a los clientes?</p>
<p>Antes de empezar, veamos lo que vamos a crear:</p>
<div class="iframe-wrapper"><iframe frameborder="0" src="http://dl.getdropbox.com/u/32709/googlemaps/index.html" style="height: 300px; width: 500px;">Please upgrade your browser</iframe></div>
<h2>Google Maps API</h2>
<p>La API Google Maps te permite embeber mapas directamente en tu sitio web. S&oacute;lo se necesita un poco de JavaScript, y algo de CSS para embellecer. Recientemente ha sido lanzada la <a title="Google Maps API V3" href="http://code.google.com/apis/maps/documentation/v3/" target="_blank">Version 3</a> de la API Google Maps que es la que vamos a utilizar.</p>
<h2>Obteniendo las coordenadas</h2>
<p>Como seguramente no conocen las coordenadas precisas de su locaci&oacute;n, les explicaremos una forma r&aacute;pida que Google ha puesto a nuestra disposici&oacute;n para conocerlas. Cuando conoces la direcci&oacute;n exacta, puedes ingresar una URL de esta forma:</p>
<div class="igBar"><span id="lphp-1"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-1'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-1">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">http:<span style="color: rgb(255, 153, 51); font-style: italic;">//maps.google.com/maps/geo?q=1+Infinite Liip,+Cupertino,+CA+95014,+USA&amp;amp;output=csv&amp;amp;oe=utf8&amp;amp;sensor=false&amp;amp;key=your_google_maps_api_key </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>Cuando ingreses esto en tu barra de direcciones, ver&aacute;s lo siguiente:</p>
<p><a title="&quot;The coordinates of Apple's head quarter in Cupertino&quot; " href="http://stiern.com/site/wp-content/everything/apple_coordinates.png"><img width="245" height="28" class="alignnone size-full wp-image-11105" src="http://www.elwebmaster.com/wp-content/uploads/2009/10/apple_coordinates.png" alt="apple_coordinates" /><br />
</a></p>
<p><em>Las coordenadas del cuartel general de Apple en Cupertino</em></p>
<p>El primer n&uacute;mero es el c&oacute;digo del estado en el que est&aacute; el punto del mapa seg&uacute;n Google, y 200 quiere decir que todo est&aacute; bien. El segundo n&uacute;mero muestra cu&aacute;n precisa es la direcci&oacute;n, en este caso el n&uacute;mero es 8, que es bastante bueno. Los &uacute;ltimos dos n&uacute;meros son latitudes y longitudes, que son los n&uacute;meros que necesitamos.</p>
<h2>A&ntilde;adiendo el mapa a tu web</h2>
<p>Abre tu editor HTML favorito y crea un archivo HTML est&aacute;ndar con codificaci&oacute;n UTF-8.</p>
<p>Primero que nada es necesario crear el puerto de visualizaci&oacute;n y decirle a nuestro archivo HTML que obtenga el archivo Javascript del c&oacute;digo Google.</p>
<p>A&ntilde;ade estas l&iacute;neas entre &lt;head&gt; y &lt;/head&gt;:</p>
<div class="igBar"><span id="lphp-2"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&lt;script src=<span style="color: rgb(255, 0, 0);">&quot;http://maps.google.com/maps/api/js?sensor=false&quot;</span> type=<span style="color: rgb(255, 0, 0);">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Luego de la URL, notar&aacute;s sensor=false. Dado que no utilizamos ning&uacute;n sensor, como un GPS, para localizar el lugar, esto se programa en false. Justo debajo de lo que hemos insertado, escriban lo siguiente:</p>
<div class="igBar"><span id="lphp-3"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-3">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&lt;script type=<span style="color: rgb(255, 0, 0);">&quot;text/javascript&quot;</span>&gt;&lt;!&#8211;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">function</span> initialize<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span> <span style="color: rgb(0, 102, 0); font-weight: bold;">{</span></div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> latlng = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.LatLng<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">57</span>.<span style="color: rgb(128, 0, 0);">0442</span>, <span style="color: rgb(128, 0, 0);">9</span>.<span style="color: rgb(128, 0, 0);">9116</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> settings = <span style="color: rgb(0, 102, 0); font-weight: bold;">{</span></div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; zoom: <span style="color: rgb(128, 0, 0);">15</span>,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; center: latlng,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapTypeControl: <span style="color: rgb(0, 0, 0); font-weight: bold;">true</span>,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapTypeControlOptions: <span style="color: rgb(0, 102, 0); font-weight: bold;">{</span>style: google.maps.MapTypeControlStyle.DROPDOWN_MENU<span style="color: rgb(0, 102, 0); font-weight: bold;">}</span>,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; navigationControl: <span style="color: rgb(0, 0, 0); font-weight: bold;">true</span>,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; navigationControlOptions: <span style="color: rgb(0, 102, 0); font-weight: bold;">{</span>style: google.maps.NavigationControlStyle.SMALL<span style="color: rgb(0, 102, 0); font-weight: bold;">}</span>,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapTypeId: google.maps.MapTypeId.ROADMAP</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(0, 102, 0); font-weight: bold;">}</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<p>En la l&iacute;nea 2 creamos la funci&oacute;n initialize(). Dentro de esta function vamos a definir las configuraciones b&aacute;sicas del mapa. En la l&iacute;nea 3 creamos una nueva variable, latlng. latlng que representa las latitudes y longitudes. La variable contiene las coordenadas que utilizaremos como centro de nuestro mapa.</p>
<p>Luego de esto creamos la variable settings. Aqu&iacute; tenemos muchas opciones.</p>
<ul>
<li>zoom espec&iacute;fica cu&aacute;nto zoom tundra el mapa.</li>
<li>center espec&iacute;fica nuestro centro. Al escribir latlng, nos referemos a la variable que hemos creado antes y se utilizar&aacute; la coordenada dentro de &eacute;sta.</li>
</ul>
<p>El &uacute;ltimo c&oacute;digo cambia el dise&ntilde;o del mapa para que sea un poco m&aacute;s minimalista. Los controles en la esquina superior derecha (Map, Satellite, Terrain) se cambian por un menu desplegable y los controles de navegaci&oacute;n/escalamiento en el lado izquierdo se cambiar por controles peque&ntilde;os.</p>
<p>mapTypeId: google.maps.MapTypeId.ROADMAP define que nuestro mapa debe ser del tipo ROADMAP &#8211; lo puedes cambiar por SATELLITE, HYBRID o TERRAIN.</p>
<p>Debajo del c&oacute;digo anterior, escriban esto:</p>
<div class="igBar"><span id="lphp-4"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> map = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Map<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span>document.getElementById<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(255, 0, 0);">&quot;map_canvas&quot;</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>, settings<span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Este c&oacute;digo crea la variable map, y define que el mapa debe utilizar las configuraciones que hemos creado.</p>
<p>Escriban:</p>
<div class="igBar"><span id="lphp-5"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-5">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 102, 0); font-weight: bold;">}</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;/script&gt;</span></div>
</li>
</ol>
</div>
</div>
</div>
<p>Para terminar la funci&oacute;n, y en <code>body</code>, escriban esto:</p>
<div class="igBar"><span id="lphp-6"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-6">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&lt;body onload=<span style="color: rgb(255, 0, 0);">&quot;initialize()&quot;</span>&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &lt;div id=<span style="color: rgb(255, 0, 0);">&quot;map_canvas&quot;</span> style=<span style="color: rgb(255, 0, 0);">&quot;width:800px; height:500px&quot;</span>&gt;&lt;/div&gt;</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&lt;/body&gt;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Al hacer esto le decimos a nuestro sitio que ejecute la funci&oacute;n <code>the initialize()</code> al cargar, y que inserte un <code>div</code> con el tama&ntilde;o que deseamos que tenga nuestro mapa.</p>
<h2>A&ntilde;adiendo marcadores</h2>
<p>Ahora debemos a&ntilde;adir algunos marcadores. Comencemos por crear los est&aacute;ndar y luego los personalizaremos.</p>
<p>Justo debajo de:</p>
<div class="igBar"><span id="lphp-7"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-7">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> map = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Map<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span>document.getElementById<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(255, 0, 0);">&quot;map_canvas&quot;</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>, settings<span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Inserten el siguiente c&oacute;digo:</p>
<div class="igBar"><span id="lphp-8"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> companyPos = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.LatLng<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">57</span>.<span style="color: rgb(128, 0, 0);">0442</span>, <span style="color: rgb(128, 0, 0);">9</span>.<span style="color: rgb(128, 0, 0);">9116</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> companyMarker = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Marker<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(0, 102, 0); font-weight: bold;">{</span></div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; position: companyPos,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; map: map,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; title:<span style="color: rgb(255, 0, 0);">&quot;Some title&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; <span style="color: rgb(0, 102, 0); font-weight: bold;">}</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Primero, hemos creado la variable <code>companyPos</code>, donde especificamos la posici&oacute;n del marcador. Luego hemos creado al marcador en s&iacute; utilizando la variable <code>companyMarker</code>.</p>
<h2>Personalizando los marcadores</h2>
<p>Podemos hacer mucho m&aacute;s bonitos nuestros marcadores. Simplemente creemos una imagen en Photoshop con un tama&ntilde;o de 100&times;50 p&iacute;xeles, y creemos algo similar a esto:</p>
<p><img width="100" height="50" class="alignnone size-full wp-image-11106" src="http://www.elwebmaster.com/wp-content/uploads/2009/10/logo.png" alt="logo" /></p>
<p>Luego, creemos una sombra para la imagen:</p>
<p><img width="130" height="50" class="alignnone size-full wp-image-11107" src="http://www.elwebmaster.com/wp-content/uploads/2009/10/logo_shadow.png" alt="logo_shadow" /></p>
<p>Para a&ntilde;adir estas im&aacute;genes como marcadores, tenemos que cambiar el c&oacute;digo del marcador por esto:</p>
<div class="igBar"><span id="lphp-9"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-9">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> companyLogo = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.MarkerImage<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(255, 0, 0);">&#8216;images/logo.png&#8217;</span>,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Size<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">100</span>,<span style="color: rgb(128, 0, 0);">50</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Point<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">0</span>,<span style="color: rgb(128, 0, 0);">0</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Point<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">50</span>,<span style="color: rgb(128, 0, 0);">50</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span></div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> companyShadow = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.MarkerImage<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(255, 0, 0);">&#8216;images/logo_shadow.png&#8217;</span>,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Size<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">130</span>,<span style="color: rgb(128, 0, 0);">50</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Point<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">0</span>,<span style="color: rgb(128, 0, 0);">0</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Point<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">65</span>, <span style="color: rgb(128, 0, 0);">50</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> companyPos = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.LatLng<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(128, 0, 0);">57</span>.<span style="color: rgb(128, 0, 0);">0442</span>, <span style="color: rgb(128, 0, 0);">9</span>.<span style="color: rgb(128, 0, 0);">9116</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> companyMarker = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Marker<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(0, 102, 0); font-weight: bold;">{</span></div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; position: companyPos,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; map: map,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; icon: companyLogo,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; shadow: companyShadow,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; title:<span style="color: rgb(255, 0, 0);">&quot;Company Title&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 102, 0); font-weight: bold;">}</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<p>La variable <code>companyImage</code> apunta al nombre de la imagen del logo. Luego define el tama&ntilde;o, origen y el tip de la imagen (d&oacute;nde estar&aacute; la imagen a&ntilde;adida a la coordenada). Luego, hacemos exactamente lo mismo para la sombra en la variable <code>companyShadow</code>. En la variable <code>companyMarker</code> a&ntilde;adimos icon y shadow, y listo.</p>
<p>Ahora, si actualizas tu sitio ver&aacute;s que el marcador ha cambiado por tu propio logo. Para a&ntilde;adir m&aacute;s marcadores, sigue simplemente el mismo m&eacute;todo, cambiando los nombres de las variables.</p>
<p>Si tienes dos marcadores muy cerca el uno del otro, quiz&aacute; debas agregar algo de <code>z-index</code>. El marcador con el <code>z-index</code> m&aacute;s alto, es el que m&aacute;s arriba est&aacute;:</p>
<p><img width="147" height="87" class="alignnone size-full wp-image-11108" src="http://www.elwebmaster.com/wp-content/uploads/2009/10/zindex.png" alt="zindex" /></p>
<p>A&ntilde;adir <code>zIndex</code> nos permite seleccionar qu&eacute; marcador debe ir arriba.</p>
<div class="igBar"><span id="lphp-10"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-10">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> companyMarker = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.Marker<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(0, 102, 0); font-weight: bold;">{</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">position: companyPos,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">map: map,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">icon: companyImage,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">shadow: companyShadow,</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">title:<span style="color: rgb(255, 0, 0);">&quot;H&oslash;genhaug&quot;</span>,</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">zIndex: <span style="color: rgb(128, 0, 0);">4</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 102, 0); font-weight: bold;">}</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<h2>A&ntilde;adiendo cajas de informaci&oacute;n</h2>
<p>Para a&ntilde;adir una descripci&oacute;n de tu compa&ntilde;&iacute;a que aparezca cuando un visitante hace clic en el logo podemos agregar un infobox. Con la API Google Maps esto es f&aacute;cilisimo.</p>
<p><img width="500" height="398" class="alignnone size-full wp-image-11109" src="http://www.elwebmaster.com/wp-content/uploads/2009/10/infobox.png" alt="infobox" /></p>
<p>Peguemos este c&oacute;digo luego de definir la variable map:</p>
<div class="igBar"><span id="lphp-11"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-11">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> contentString = <span style="color: rgb(255, 0, 0);">&#8216;&lt;div id=&quot;content&quot;&gt;&#8217;</span>+</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(255, 0, 0);">&#8216;&lt;div id=&quot;siteNotice&quot;&gt;&#8217;</span>+</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(255, 0, 0);">&#8216;&lt;/div&gt;&#8217;</span>+</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(255, 0, 0);">&#8216;&lt;h1 id=&quot;firstHeading&quot; class=&quot;firstHeading&quot;&gt;H&oslash;genhaug&lt;/h1&gt;&#8217;</span>+</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(255, 0, 0);">&#8216;&lt;div id=&quot;bodyContent&quot;&gt;&#8217;</span>+</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(255, 0, 0);">&#8216;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.&lt;/p&gt;&#8217;</span>+</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(255, 0, 0);">&#8216;&lt;/div&gt;&#8217;</span>+</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: rgb(255, 0, 0);">&#8216;&lt;/div&gt;&#8217;</span>;</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">var</span> infowindow = <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> google.maps.InfoWindow<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(0, 102, 0); font-weight: bold;">{</span></div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">&nbsp; &nbsp; content: contentString</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 102, 0); font-weight: bold;">}</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Para hacer que las cajas de informaci&oacute;n aparezcan al hacer clic en nuestro logo, simplemente debemos a&ntilde;adir este c&oacute;digo justo antes del &uacute;ltimo } en la funci&oacute;n <code>initialize()</code>:</p>
<div class="igBar"><span id="lphp-12"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('php-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="php-12">
<div class="php">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">google.maps.event.addListener<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span>companyMarker, <span style="color: rgb(255, 0, 0);">&#8216;click&#8217;</span>, <span style="color: rgb(0, 0, 0); font-weight: bold;">function</span><span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span> <span style="color: rgb(0, 102, 0); font-weight: bold;">{</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">infowindow.open<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span>map,companyMarker<span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 102, 0); font-weight: bold;">}</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Para hacer un poco m&aacute;s bonita la caja de informaci&oacute;n, a&ntilde;adamos algo de estilo en nuestra hoja de estilos:</p>
<div class="igBar"><span id="lcss-13"><a href="http://www.elwebmaster.com/general/insertar-y-personalizar-google-maps-en-tu-sitio-web#" onclick="javascript:showPlainTxt('css-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="css-13">
<div class="css">
<ol>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;">body <span style="color: rgb(102, 204, 102);">{</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">font-family</span>: Helvetica, Arial, <span style="color: rgb(153, 51, 51);">sans-serif</span>;</div>
</li>
<li style="font-family: 'Courier New',Courier,monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(0, 0, 0); font-weight: bold;">font-size</span>:10pt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal;"><span style="color: rgb(102, 204, 102);">}</span></div>
</li>
</ol>
</div>
</div>
</div>
<p>Y ah&iacute; lo tienen. Un Google Map bonito y f&aacute;cilmente a&ntilde;adido en tu sitio web o blog.</p>
<h2>Descarga</h2>
<p>Para descargar los archivos de muestra hagan <a href="http://dl.getdropbox.com/u/32709/googlemaps.zip" target="_blank">clic aqu&iacute;</a>.</p>
<p>Fuente: <a href="http://stiern.com/tutorials/adding-custom-google-maps-to-your-website" target="_blank">Stiern</a></p>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2009/11/google-maps-api-personaliza-tu-mapa/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Programación de un modulo del kernel simple</title>
		<link>http://smultron.es/2009/10/programacion-de-un-modulo-del-kernel-simple/</link>
		<comments>http://smultron.es/2009/10/programacion-de-un-modulo-del-kernel-simple/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 08:32:18 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4579</guid>
		<description><![CDATA[&#160; Copy&#38;Page: http://systemadmin.es/2009/09/programacion-de-un-modulo-del-kernel-simple Programaci&#243;n de un modulo del kernel simple La programaci&#243;n de un m&#243;dulo del kernel de Linux no es tan diferente de la programaci&#243;n de cualquier otro software, simplemente los errores se suelen pagar m&#225;s caros. Vamos a ver el t&#237;pico Hello World como m&#243;dulo del kernel: Primero de todo deberemos incluir algunos [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Copy&amp;Page: http://systemadmin.es/2009/09/programacion-de-un-modulo-del-kernel-simple</p>
<p><span id="more-4579"></span></p>
<h1>Programaci&oacute;n de un modulo del kernel simple</h1>
<p>La programaci&oacute;n de un m&oacute;dulo del <strong>kernel de Linux</strong> no es tan diferente de la programaci&oacute;n de cualquier otro software, simplemente los errores se suelen pagar m&aacute;s caros. Vamos a ver el t&iacute;pico <strong>Hello World</strong> como <strong>m&oacute;dulo del kernel</strong>:</p>
<p><!-- more --></p>
<p>Primero de todo deberemos incluir algunos <strong>headers</strong> que contienen definiciones que vamos a necesitar:</p>
<pre>
#include &lt;linux/init.h&gt;
#include &lt;linux/module.h&gt;
</pre>
<p>A continuaci&oacute;n deberemos definir la <strong>licencia del modulo</strong>:</p>
<pre>
MODULE_LICENSE(&quot;GPL&quot;);
</pre>
<p>Si nos la inventamos simplemente nos avisara al hacer el <strong>insmod</strong>:</p>
<pre>
helloworld: module license 'xGPL' taints kernel.
</pre>
<p>A continuaci&oacute;n deberemos definir las funciones de inicializaci&oacute;n i destrucci&oacute;n del modulo en las cuales para este sencillo ejemplo haremos un simple <strong>printk</strong> (equivalente de <strong>printf</strong> en el kernel):</p>
<pre>
static int hello_world_init(void)
{
        printk(KERN_ALERT &quot;Hello World!\n&quot;);
        return 0;
}
</pre>
<p>En la funci&oacute;n de destrucci&oacute;n haremos lo mismo:</p>
<pre>
static void hello_world_exit(void)
{
        printk(KERN_ALERT &quot;Bye World!\n&quot;);
}
</pre>
<p>Finalmente deberemos indicar como hemos llamado a las funciones mediante <strong>module_init</strong> y <strong>module exit</strong>:</p>
<pre>
module_init(hello_world_init);
module_exit(hello_world_exit);
</pre>
<p>Finalmente deberemos crear el fichero de <strong>Makefile</strong>:</p>
<pre>
obj-m += helloworld.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
</pre>
<p>Es obligatorio que antes de los comandos &ldquo;<strong>make</strong>&rdquo; haya un tabulador y no un conjunto de espacios, sino no va a reconocer el formato del <strong>Makefile</strong>.</p>
<p>Con el comando <strong>make</strong> vamos a compilar el <strong>modulo del kernel</strong>:</p>
<pre>
# make
make -C /lib/modules/2.6.18-53.1.21.el5PAE/build M=/home/jordi/helloworld modules
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.1.21.el5-PAE-i686'
  CC [M]  /home/jordi/helloworld/helloworld.o
  Building modules, stage 2.
  MODPOST
  CC      /home/jordi/helloworld/helloworld.mod.o
  LD [M]  /home/jordi/helloworld/helloworld.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.1.21.el5-PAE-i686'
</pre>
<p>Mediante un <strong>ls</strong> podemos ver los ficheros que ha generado:</p>
<pre>
# ls
helloworld.c  helloworld.ko  helloworld.mod.c  helloworld.mod.o  helloworld.o  Makefile  Module.symvers
</pre>
<p>Podemos cargar el m&oacute;dulo mediante <strong>insmod</strong>:</p>
<pre>
insmod helloworld.ko
</pre>
<p>A continuaci&oacute;n mediante el <strong>dmesg</strong> podremos ver el <strong>Hello World</strong>:</p>
<pre>
audit(1254211500.001:3472101): user pid=1772 uid=0 auid=0 msg='insmod helloworld.ko '
Hello World!
</pre>
<p>Una forma de ver que el m&oacute;dulo esta cargado es mediante <strong>lsmod</strong>:</p>
<pre>
# lsmod  | grep hel
helloworld              5504  0
</pre>
<p>Para ver el &ldquo;Bye World&rdquo; lo descargamos mediante <strong>rmmod</strong>:</p>
<pre>
rmmod helloworld
</pre>
<p>Y de nuevo, con <strong>dmesg</strong>, podremos ver el mensaje de despedida:</p>
<pre>
audit(1254211613.892:3472132): user pid=1772 uid=0 auid=0 msg='rmmod helloworld'
Bye World!
audit(1254211627.421:3472133): user pid=1772 uid=0 auid=0 msg='dmesg </pre>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2009/10/programacion-de-un-modulo-del-kernel-simple/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Seguir una llamada a sistema concreta con strace</title>
		<link>http://smultron.es/2009/10/seguir-una-llamada-a-sistema-concreta-con-strace/</link>
		<comments>http://smultron.es/2009/10/seguir-una-llamada-a-sistema-concreta-con-strace/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 08:24:17 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[copy&page]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[sistema]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4577</guid>
		<description><![CDATA[&#160; Copy&#38;Page: http://systemadmin.es/2009/09/seguir-una-llamada-a-sistema-concreta-con-strace Cuando se deben resolver problemas extra&#241;os con el sistema se suele recurrir a strace para ver que esta ocurriendo. El principal inconveniente de strace es que da mucha informaci&#243;n, lo cual puede llegar a despistar m&#225;s que ayudar. Vamos a ver como seguir una llamada concreta al sistema. Mediante el par&#225;metro -e [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Copy&amp;Page: http://systemadmin.es/2009/09/seguir-una-llamada-a-sistema-concreta-con-strace</p>
<p><span id="more-4577"></span></p>
<p>Cuando se deben resolver problemas extra&ntilde;os con el sistema se suele recurrir a <strong>strace</strong> para ver que esta ocurriendo. El principal inconveniente de <strong>strace</strong> es que da mucha informaci&oacute;n, lo cual puede llegar a despistar m&aacute;s que ayudar. Vamos a ver como seguir una llamada concreta al sistema.</p>
<p><!-- more --></p>
<p>Mediante el par&aacute;metro <strong>-e</strong> podemos indicar una expresi&oacute;n que filtre las llamadas que queremos ver. Por ejemplo, si queremos ver solo las llamadas a la funci&oacute;n <strong>open</strong> usar&iacute;amos como par&aacute;metro <strong>trace=open</strong>. El comando completo ser&iacute;a:</p>
<pre>
# strace -s 128 -fF -e trace=open ls
open(&quot;/etc/ld.so.cache&quot;, O_RDONLY)      = 3
open(&quot;/lib64/librt.so.1&quot;, O_RDONLY)     = 3
open(&quot;/lib64/libacl.so.1&quot;, O_RDONLY)    = 3
open(&quot;/lib64/libc.so.6&quot;, O_RDONLY)      = 3
open(&quot;/lib64/libpthread.so.0&quot;, O_RDONLY) = 3
open(&quot;/lib64/libattr.so.1&quot;, O_RDONLY)   = 3
open(&quot;/lib64/libdl.so.2&quot;, O_RDONLY)     = 3
open(&quot;/lib64/libsepol.so.1&quot;, O_RDONLY)  = 3
open(&quot;/proc/mounts&quot;, O_RDONLY)          = 3
open(&quot;/usr/lib/locale/locale-archive&quot;, O_RDONLY) = 3
open(&quot;.&quot;, O_RDONLY|O_NONBLOCK|O_DIRECTORY) = 3
index.php
</pre>
<p>Tambi&eacute;n podemos definir un conjunto de llamadas separadas por comas:</p>
<pre>
# strace -s 128 -fF -e trace=open,close ls
open(&quot;/etc/ld.so.cache&quot;, O_RDONLY)      = 3
close(3)                                = 0
open(&quot;/lib64/librt.so.1&quot;, O_RDONLY)     = 3
close(3)                                = 0
open(&quot;/lib64/libacl.so.1&quot;, O_RDONLY)    = 3
close(3)                                = 0                           = 0
open(&quot;/lib64/libc.so.6&quot;, O_RDONLY)      = 3
close(3)                                = 0
open(&quot;/lib64/libpthread.so.0&quot;, O_RDONLY) = 3
close(3)                                = 0
open(&quot;/lib64/libattr.so.1&quot;, O_RDONLY)   = 3
close(3)                                = 0
open(&quot;/lib64/libdl.so.2&quot;, O_RDONLY)     = 3
close(3)                                = 0
open(&quot;/lib64/libsepol.so.1&quot;, O_RDONLY)  = 3
close(3)                                = 0                            = 0
open(&quot;/proc/mounts&quot;, O_RDONLY)          = 3
close(3)                                = 0
open(&quot;/usr/lib/locale/locale-archive&quot;, O_RDONLY) = 3
close(3)                                = 0
open(&quot;.&quot;, O_RDONLY|O_NONBLOCK|O_DIRECTORY) = 3
close(3)                                = 0
index.php
close(1)                                = 0
</pre>
<p>Podemos incluso definir <strong>filtros inversos</strong>, es decir, ver todas las llamadas al sistema excepto una o un conjunto indicando una admiraci&oacute;n (<strong>!</strong>) para indicar la negaci&oacute;n del <strong>filtro</strong>. Por ejemplo, para ver todas las llamadas excepto <strong>open</strong> y <strong>close</strong> usar&iacute;amos el filtro &ldquo;<strong>trace=!open,close</strong>&ldquo;:</p>
<pre>
# strace -s 128 -fF -e 'trace=!open,close' ls
execve(&quot;/bin/ls&quot;, [&quot;ls&quot;], [/* 25 vars */]) = 0
brk(0)                                  = 0x127c3000
uname({sys=&quot;Linux&quot;, node=&quot;maria.grupointercom.com&quot;, ...}) = 0
access(&quot;/etc/ld.so.preload&quot;, R_OK)      = -1 ENOENT (No such file or directory)
fstat(3, {st_mode=S_IFREG|0644, st_size=39087, ...}) = 0
read(3, &quot;\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0&gt;\0\1\0\0\0 \&quot;`&lt;2\0\0\0@\0\0\0\0\0\0\0\10\307\0\0\0\0\0\0\0\0\0\0@\0008\0\t\0@\0'\0&amp;\0\6\0\0\0\5\0\0\0@\0\0\0\0\0\0\0@\0`&lt;2\0\0\0@\0`&lt;2\0\0\0\370\1\0\0\0\0\0\0\370\1\0\0\0\0\0\0\10\0\0\0\0\0\0\0\3\0\0\0\4\0\0\0&quot;..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=53448, ...}) = 0
mprotect(0x323c607000, 2097152, PROT_NONE) = 0
read(3, &quot;\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0&gt;\0\1\0\0\0\0\31 \2234\0\0\0@\0\0\0\0\0\0\0(f\0\0\0\0\0\0\0\0\0\0@\0008\0\5\0@\0\35\0\34\0\1\0\0\0\5\0\0\0\0\0\0\0\0\0\0\0\0\0 \2234\0\0\0\0\0 \2234\0\0\0004Y\0\0\0\0\0\0004Y\0\0\0\0\0\0\0\0 \0\0\0\0\0\1\0\0\0\6\0\0\0&quot;..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=28008, ...}) = 0
(...)
</pre>
<p><!-- Social Bookmarking Reloaded BEGIN --></p>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2009/10/seguir-una-llamada-a-sistema-concreta-con-strace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mas cosas guays sobre el comando &#8220;SED&#8221;</title>
		<link>http://smultron.es/2009/10/mas-cosas-guays-sobre-el-comando-sed/</link>
		<comments>http://smultron.es/2009/10/mas-cosas-guays-sobre-el-comando-sed/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 14:33:35 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[copy&page]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4542</guid>
		<description><![CDATA[Copy&#38;page:http://programacionbizarra.blogspot.com/2009/03/presentacion-del-sed-copyright-c-2009.html Tutorial, Gu&#237;a o Simplemente Introducci&#243;n al Comando Sed de Unix &#160; Copyright (c) 2009 H&#233;ctor Francisco Hern&#225;ndez &#60;hectorfh@gmail.com&#62;. Se otorga permiso para copiar, distribuir y/o modificar este documento bajo los t&#233;rminos de la Licencia de Documentaci&#243;n Libre de GNU, Versi&#243;n 1.3 o cualquier otra versi&#243;n posterior publicada por la Free Software Foundation; sin Secciones [...]]]></description>
			<content:encoded><![CDATA[<p>Copy&amp;page:http://programacionbizarra.blogspot.com/2009/03/presentacion-del-sed-copyright-c-2009.html</p>
<p><span id="more-4542"></span></p>
<p>Tutorial, Gu&iacute;a o Simplemente Introducci&oacute;n al Comando Sed de Unix</p>
<p>&nbsp;</p>
<p>
Copyright (c) 2009 H&eacute;ctor Francisco Hern&aacute;ndez &lt;hectorfh@gmail.com&gt;.</p>
<p>
Se otorga permiso para copiar, distribuir y/o modificar este documento bajo los t&eacute;rminos de la Licencia de Documentaci&oacute;n Libre de GNU, Versi&oacute;n 1.3 o cualquier otra versi&oacute;n posterior publicada por la Free Software Foundation; sin Secciones Invariantes ni Textos de Cubierta Delantera ni Textos de Cubierta Trasera. Una copia de la licencia se encuentra en http://www.gnu.org/copyleft/fdl.html.</p>
<p>&nbsp;</p>
<h2>1. Introducci&oacute;n</h2>
<p>&nbsp;</p>
<p>
La herramienta de Unix &quot;sed&quot; (&quot;stream editor&quot; o &quot;editor de flujo&quot;) es, junto con &quot;awk&quot; (y sin<br />
contar a Perl, la panacea, en la contienda), la m&aacute;s poderosa en lo que<br />
a procesamiento de texto plano se refiere.</p>
<p>&nbsp;</p>
<p>
Al igual que el editor &quot;ed&quot;, del cual toma todos sus comandos, permite escribir peque&ntilde;os scripts de edici&oacute;n de texto en un<br />
particular lenguaje:</p>
<p>&nbsp;</p>
<pre>
# el comando &quot;i&quot; inserta texto en la l&iacute;nea
# que se le indique
sed '7i hola mundo' zaraza.txt

# el comando &quot;d&quot; borra l&iacute;neas
sed '1d' zaraza.txt

# el comando &quot;s&quot; sustituye texto utilizando
# expresiones regulares si se desea
sed '1,$s/palavra/palabra/g' zaraza.txt
</pre>
<p>&nbsp;</p>
<p>
Sin embargo, su caracter&iacute;stica distintiva es la habilidad de procesar<br />
texto proveniente desde la entrada est&aacute;ndar. La que lo convierte en una<br />
herramienta ideal para construir filtros y utilizarlos en nuestros scripts<br />
Bourne, Korn, tcsh, bash, o lo que fuere.</p>
<p>&nbsp;</p>
<h2>2. Uso B&aacute;sico</h2>
<p>&nbsp;</p>
<p>
Las instrucciones que entiende &quot;sed&quot; est&aacute;n compuestas primero por el<br />
n&uacute;mero o rango de l&iacute;neas sobre el cual se realizar&aacute; la transformaci&oacute;n y<br />
luego por la acci&oacute;n a realizar. Omitir el n&uacute;mero o rango de l&iacute;neas<br />
implicar&aacute; que la acci&oacute;n se ejecute sobre la totalidad de las mismas.</p>
<p>&nbsp;</p>
<p>
De este modo si, por ejemplo, disponemos del siguiente listado obtenido por el<br />
comando &quot;ps&quot;:</p>
<p>&nbsp;</p>
<pre>
 PID   TTY TIME     CMD
6245 pts/1 00:00:00 bash
6246 pts/1 00:00:00 ps
</pre>
<p>&nbsp;</p>
<p>
Y para procesar el listado queremos suprimir los t&iacute;tulos,<br />
podr&iacute;amos eliminar la primera l&iacute;nea con la instrucci&oacute;n<br />
&quot;1d&quot;. Por lo tanto nuestro comando en el shell ser&iacute;a<br />
&quot;ps | sed &#8217;1d&#8217;&quot; y obtendr&iacute;amos:</p>
<p>&nbsp;</p>
<pre>
6245 pts/1 00:00:00 bash
6246 pts/1 00:00:00 ps
</pre>
<p>&nbsp;</p>
<p>
Los rangos de l&iacute;neas son de la forma &quot;n,m&quot; que significa<br />
&quot;desde la l&iacute;nea n inclusive hasta la l&iacute;nea m&quot;.<br />
Pudiendo &quot;m&quot; ser el s&iacute;mbolo especial &quot;$&quot; que<br />
indica el final del archivo.</p>
<p>&nbsp;</p>
<p>
As&iacute;, por ejemplo, si quisi&eacute;ramos, como generalmente ocurre,<br />
obtener desde la l&iacute;nea 74 hasta la 83 de un archivo de texto denominado<br />
&quot;xxx&quot; podr&iacute;amos hacerlo con la instrucci&oacute;n<br />
&quot;74,83p&quot; as&iacute;:</p>
<p>&nbsp;</p>
<pre>
sed -n '74,83p' xxx
</pre>
<p>&nbsp;</p>
<p>
En este ejemplo debo hacer notar el par&aacute;metro &quot;-n&quot;. Por<br />
defecto &quot;sed&quot; imprime todo a la salida est&aacute;ndar, s&oacute;lo<br />
que &quot;-n&quot; modifica este comportamiento para que no lo haga. Por lo<br />
tanto, si no us&aacute;ramos el par&aacute;metro &quot;-n&quot;<br />
obtendr&iacute;amos todo el archivo &quot;xxx&quot; con las<br />
l&iacute;neas desde la 74 hasta la 83 duplicadas, ya que la instrucci&oacute;n<br />
&quot;p&quot; volver&iacute;a a imprimirlas.</p>
<p>&nbsp;</p>
<p>
No s&oacute;lo es posible indicar un n&uacute;mero de l&iacute;nea o un rango num&eacute;rico,<br />
tambi&eacute;n es posible indicar una expresi&oacute;n regular o un rango de<br />
expresiones regulares.</p>
<p>&nbsp;</p>
<p>
Cuando queremos que la acci&oacute;n se ejecute sobre las l&iacute;neas que<br />
coincidan con una expresi&oacute;n determinada, debemos escribirla delante del<br />
comando entre barras:</p>
<p>&nbsp;</p>
<pre>
# imprime s&oacute;lo las l&iacute;neas que tengan la
# palabra &quot;proc&quot;, lo mismo que har&iacute;a el
# comando &quot;grep proc&quot;
sed -n '/proc/p'

# borra lo que se encuentre entre
# &quot;#ifdef __WIN32__&quot; y &quot;#endif&quot;
sed '/#ifdef __WIN32__/,/#endif/d'
</pre>
<p>&nbsp;</p>
<p>
De este modo, por ejemplo, si disponemos del siguiente listado arrojado por<br />
&quot;ls&quot;:</p>
<p>&nbsp;</p>
<pre>
total 888
-rw-r--r--  1 usuario1 users   2737 2003-04-01 04:36 LICENSE.txt
-rw-r--r--  1 usuario1 users   3639 2003-04-01 04:36 README.txt
drwxr-xr-x  4 usuario1 users   4096 2007-09-08 21:52 build
drwxr-xr-x  2 usuario1 users   4096 2007-09-08 21:52 convert
drwxr-xr-x  5 usuario1 users   4096 2007-09-08 21:52 docs
drwxr-xr-x 12 usuario1 users   4096 2007-09-08 21:52 examples
drwxr-xr-x  3 usuario1 users   4096 2003-04-01 04:35 src
drwxr-xr-x 12 usuario1 users   4096 2003-04-01 04:36 test
-rw-r--r--  1 usuario1 users 351405 2003-04-01 04:36 velocity-1.3.1.jar
-rw-r--r--  1 usuario1 users 510105 2003-04-01 04:36 velocity-dep-1.3.1.jar
drwxr-xr-x  5 usuario1 users   4096 2007-09-08 21:52 xdocs
</pre>
<p>&nbsp;</p>
<p>
Y queremos obtener un listado s&oacute;lo de los directorios (las filas que<br />
comienzan con la letra &quot;d&quot;). Podr&iacute;amos utilizar el sed para<br />
borrar las entradas que no comienzan con esa letra:<br />
&quot;ls -l | sed &#8216;/^d/!d&#8217;&quot;:</p>
<p>&nbsp;</p>
<pre>
drwxr-xr-x  4 usuario1 users 4096 2007-09-08 21:52 build
drwxr-xr-x  2 usuario1 users 4096 2007-09-08 21:52 convert
drwxr-xr-x  5 usuario1 users 4096 2007-09-08 21:52 docs
drwxr-xr-x 12 usuario1 users 4096 2007-09-08 21:52 examples
drwxr-xr-x  3 usuario1 users 4096 2003-04-01 04:35 src
drwxr-xr-x 12 usuario1 users 4096 2003-04-01 04:36 test
drwxr-xr-x  5 usuario1 users 4096 2007-09-08 21:52 xdocs
</pre>
<p>&nbsp;</p>
<p>
Note que el s&iacute;mbolo de exclamaci&oacute;n &quot;!&quot; detr&aacute;s<br />
de la expresi&oacute;n regular niega la condici&oacute;n. Esto deber&iacute;a<br />
leerse como &quot;borre todas las l&iacute;neas que no comiencen con la letra<br />
d&quot;.</p>
<p>&nbsp;</p>
<p>
Otra forma de obtener el mismo resultado es imprimiendo s&oacute;lo<br />
las l&iacute;neas que comienzan con la letra &quot;d&quot;:</p>
<p>&nbsp;</p>
<pre>
ls -l | sed -n '/^d/p'
</pre>
<p>&nbsp;</p>
<p>
Explicar las expresiones regulares va m&aacute;s all&aacute; de los<br />
l&iacute;mites de este art&iacute;culo, pero el car&aacute;cter &quot;^&quot;<br />
significa &quot;comienzo de l&iacute;nea&quot;, por lo tanto &quot;^d&quot;<br />
hace referencia a las l&iacute;neas que poseen una &quot;d&quot; seguida de<br />
su comienzo.</p>
<p>&nbsp;</p>
<h2>3. Lo M&aacute;s Importante: El Comando &quot;s&quot;</h2>
<p>&nbsp;</p>
<p>
El comando &quot;s&quot; sustituye expresiones regulares en la l&iacute;nea actual.<br />
Este comando por s&iacute; s&oacute;lo ser&iacute;a justificaci&oacute;n para<br />
la existencia del sed.</p>
<p>&nbsp;</p>
<p>
El modo de uso de este comando es &quot;s/patr&oacute;n/reemplazo/flags&quot;. Donde<br />
&quot;patr&oacute;n&quot; es la expresi&oacute;n regular que debe sustituirse por<br />
&quot;reemplazo&quot; y los flags son modificadores opcionales que indican, por ejemplo,<br />
si la b&uacute;squeda debe discriminar entre may&uacute;sculas y<br />
min&uacute;sculas o no.</p>
<p>&nbsp;</p>
<p>
Siguiendo mi uso de explicar con ejemplos, suponga que posee un texto donde<br />
las palabras podr&iacute;an estar separadas por m&aacute;s de un espacio:</p>
<p>&nbsp;</p>
<pre>
Aqu&iacute;   me pongo a   cantar
al  comp&aacute;s de    la vig&uuml;ela,
que al hombre  que lo desvela
una   pena     estrordinaria,
como la ave solitaria
con    el cantar se   consuela.
</pre>
<p>&nbsp;</p>
<p>
Sin embargo usted necesita, por alguna extra&ntilde;a raz&oacute;n que ahora no<br />
se me ocurre, que est&eacute;n separadas por exactamente un &uacute;nico<br />
espacio. Podr&iacute;a sustituir el patr&oacute;n &quot;uno o m&aacute;s espacios&quot;<br />
por un &uacute;nico espacio. El comando ser&iacute;a:</p>
<p>&nbsp;</p>
<pre>
sed 's/ \+/ /g'
</pre>
<p>&nbsp;</p>
<p>
El &quot;\+&quot; luego de un car&aacute;cter significa una o m&aacute;s ocurrencias de<br />
ese car&aacute;cter (se recomienda leer sobre expresiones regulares en general).<br />
La letra &quot;g&quot; al final es un flag que hace que se sustituyan todos los patrones<br />
encontrados en cada l&iacute;nea. Sin &eacute;l s&oacute;lo se<br />
sustituir&aacute; la primera ocurrencia en cada rengl&oacute;n del texto.</p>
<p>&nbsp;</p>
<p>
El resultado:</p>
<p>&nbsp;</p>
<pre>
Aqu&iacute; me pongo a cantar
al comp&aacute;s de la vig&uuml;ela,
que al hombre que lo desvela
una pena estrordinaria,
como la ave solitaria
con el cantar se consuela.
</pre>
<p>&nbsp;</p>
<p>
Y as&iacute; tambi&eacute;n es posible hacer referencia al &quot;patr&oacute;n&quot; o a<br />
&quot;subpatrones&quot; en el &quot;reemplazo&quot; mediante los car&aacute;cteres especiales<br />
&quot;\&amp;&quot; y &quot;\1&quot;, &quot;\2&quot;, &quot;\3&quot;&#8230; &quot;\n&quot; respectivamente. Por ejemplo, suponga que<br />
posee la siguiente lista en la que cada elemento es de la forma<br />
&quot;archivo@direcorio&quot;:</p>
<p>&nbsp;</p>
<pre>
libhardware.a@dosbox-0.70/src/hardware
Makefile.in@dosbox-0.70/src/libs
video.h@dosbox-0.70/include
README.video@dosbox-0.70/docs
Makefile@dosbox-0.70/visualc_net
</pre>
<p>&nbsp;</p>
<p>
Luego de aplicarle a la lista &quot;sed &#8216;s_\(.*\)@\(.*\)_\2/\1_&#8217;&quot;, obtenemos:</p>
<p>&nbsp;</p>
<pre>
dosbox-0.70/src/hardware/libhardware.a
dosbox-0.70/src/libs/Makefile.in
dosbox-0.70/include/video.h
dosbox-0.70/docs/README.video
dosbox-0.70/visualc_net/Makefile
</pre>
<p>&nbsp;</p>
<p>
Esto significa que &quot;\1&quot; hace referencia al subpatr&oacute;n que se encuentra<br />
entre los primeros par&eacute;ntesis y que &quot;\2&quot; hace referencia al<br />
subpatr&oacute;n entre los segundos par&eacute;ntesis. F&iacute;jese<br />
tambi&eacute;n que en lugar de separar los par&aacute;metros del comando con<br />
una barra &quot;/&quot; lo hice con &quot;_&quot;. Esto es porque sed nos permite utilizar cualquier<br />
car&aacute;cter como separador y se dar&aacute; cuenta autom&aacute;ticamente<br />
de cu&aacute;l estamos usando.</p>
<p>&nbsp;</p>
<p>
Aunque el ejemplo que acabo de ense&ntilde;ar parece est&uacute;pido,<br />
cr&eacute;ame que es real y que para un trabajo me ha tocado hacer un script<br />
que le&iacute;a una lista con esa estructura.</p>
<p>&nbsp;</p>
<h2>4. Procesando Varias L&iacute;neas por Vez</h2>
<p>&nbsp;</p>
<p>
Hasta el momento en todos los ejemplos que mostr&eacute; se le&iacute;a una<br />
l&iacute;nea, se chequeaba una condici&oacute;n y se realizaba una<br />
operaci&oacute;n. Y as&iacute; cada operaci&oacute;n involucraba una<br />
&uacute;nica l&iacute;nea.</p>
<p>&nbsp;</p>
<p>
Existen, sin embargo, circunstancias en las que es necesario operar sobre<br />
m&aacute;s de una l&iacute;nea por vez. Observe el siguiente archivo:</p>
<p>&nbsp;</p>
<pre>
Registro: 1
Nombre: Anibal
Telefono: 621-229

Registro: 2
Nombre: Hector
Telefono: 562-245

Registro: 3
Nombre: Pablo
Telefono: 622-354
</pre>
<p>&nbsp;</p>
<p>
Alguien ha decidido guardar una lista de personas con sus n&uacute;meros<br />
de tel&eacute;fonos en un extra&ntilde;o formato, utilizando cuatro<br />
l&iacute;neas por registro.<br />
Nuestra tarea es poner la informaci&oacute;n en una manera m&aacute;s<br />
conveniente para su procesamiento:</p>
<p>&nbsp;</p>
<pre>
1;Anibal;621-229
2;Hector;562-245
3;Pablo;622-354
</pre>
<p>&nbsp;</p>
<p>
Claro est&aacute; que ser&iacute;a imposible<br />
solucionar este problema leyendo de a una l&iacute;nea a la vez. Ser&iacute;a<br />
bueno poder trabajar leyendo de a un registro (cuatro l&iacute;neas) por<br />
iteraci&oacute;n.</p>
<p>&nbsp;</p>
<p>
Este tipo de problemas se resuelve con el comando &quot;N&quot;, que fuerza<br />
la lectura<br />
de la siguiente l&iacute;nea en la iteraci&oacute;n actual.</p>
<p>&nbsp;</p>
<p>
Al comenzar la iteraci&oacute;n, sed trae la l&iacute;nea al buffer.<br />
Internamente el valor del buffer ser&iacute;a:</p>
<p>&nbsp;</p>
<pre>
buffer = &quot;Registro: 1&quot;
</pre>
<p>&nbsp;</p>
<p>
Luego de ejecutar la instrucci&oacute;n &quot;N&quot;, que lee la<br />
l&iacute;nea siguiente y la concatena en el buffer, quedar&iacute;a:</p>
<p>&nbsp;</p>
<pre>
buffer = &quot;Registro: 1\nNombre: Anibal&quot;
</pre>
<p>&nbsp;</p>
<p>
Observe que &quot;\n&quot; significa &quot;nueva l&iacute;nea&quot;<br />
(el car&aacute;cter ASCII n&uacute;mero 10).</p>
<p>&nbsp;</p>
<p>
Como vemos, nos vamos aproximando a la soluci&oacute;n. Basta con leer<br />
dos l&iacute;neas m&aacute;s y ya tenemos el registro completo.<br />
Y luego de hacerlo debemos reemplazar el retorno de carro &quot;\n&quot;<br />
por &quot;;&quot; con &quot;s/\n/;/g&quot;, para as&iacute; llegar a:</p>
<p>&nbsp;</p>
<pre>
buffer = &quot;Registro: 1;Nombre: Anibal;Telefono: 621-229;&quot;
</pre>
<p>&nbsp;</p>
<p>
Ahora resta quitar lo que molesta, las palabras<br />
&quot;Registro: &quot;, &quot;Nombre: &quot;, &quot;Telefono: &quot; y el<br />
punto y coma de m&aacute;s al final.</p>
<p>&nbsp;</p>
<p>
Para lograrlo utilizaremos una super sustituci&oacute;n con expresiones<br />
regulares:</p>
<p>&nbsp;</p>
<pre>
&quot;s/^Registro: \(.*\);Nombre: \(.*\);Telefono: \(.*\);$/\1;\2;\3/&quot;
</pre>
<p>&nbsp;</p>
<pre>
buffer = &quot;1;Anibal;621-229&quot;
</pre>
<p>&nbsp;</p>
<p>
Ahora podr&iacute;amos poner todo junto.<br />
Suponiendo que los datos originales estaban en el archivo &quot;agenda&quot;,<br />
nuestro comando quedar&iacute;a:</p>
<p>&nbsp;</p>
<pre>
sed 'N;N;N;s/\n/;/g;s/^Registro: \(.*\);Nombre: \(.*\);Telefono: \(.*\);$/\1;\2;\3/' agenda
</pre>
<p>&nbsp;</p>
<p>
Ilegible, &iquest;verdad? Si as&iacute; lo considera, puede hacerlo en dos<br />
pasos invocando dos veces al sed.</p>
<p>&nbsp;</p>
<h2>5. Programaci&oacute;n en Sed</h2>
<p>&nbsp;</p>
<p>
En la documentaci&oacute;n del sed de GNU, el cap&iacute;tulo que explica esto dice<br />
&quot;Comandos para gur&uacute;es del sed &#8230; En la mayor&iacute;a de los casos, el uso de<br />
estos comandos indican que probablemente sea mejor programar en awk o Perl&quot;.<br />
La raz&oacute;n por la cual ense&ntilde;o estos comandos es para mostrar el l&iacute;mite de la herramienta.</p>
<p>&nbsp;</p>
<p>
A pesar de no tener variables ni poseer forma de controlar el flujo de<br />
ejecuci&oacute;n m&aacute;s que con etiquetas, un comando para &quot;GOTO&quot; y otro<br />
para &quot;GOTO&quot; condicional, sed es un lenguaje &quot;Turing-completo&quot;. Esto es que<br />
tiene un poder computacional equivalente a la m&aacute;quina universal de<br />
Turing. Por eso circula un mito nerd de que en alg&uacute;n lugar de la web<br />
se puede descargar los fuentes de un sokoban, un arkanoid y alg&uacute;n otro<br />
juego cl&aacute;sico implementado en sed.</p>
<p>&nbsp;</p>
<p>
Los comandos para hacer un &quot;GOTO&quot; incondicional y condicional son &quot;b&quot; y &quot;t&quot;<br />
respectivamente. Las etiquetas se definen con el comando &quot;:&quot;. Adem&aacute;s<br />
sed posee un buffer denominado &quot;hold space&quot; que provee un espacio adicional para<br />
almacenar datos sobre el cual podremos guardar y recuperar lo que pongamos con<br />
los comandos h, H, g, G, x. Refi&eacute;ranse a la documentaci&oacute;n del sed<br />
los interesados, pues no tengo inter&eacute;s en explicar sobre este asunto.</p>
<p>&nbsp;</p>
<p>
Imaginese que sin variables, sin estructuras de control y sin operadores<br />
aritm&eacute;ticos entre otras cosas,<br />
la programaci&oacute;n en sed no es m&aacute;s que otro aburrido juego de<br />
ingenio para simios. Por este motivo ser&aacute; que finalizar&eacute; este<br />
cap&iacute;tulo copi&aacute;ndole un script del tutorial &quot;Sed &#8211; An Introduction and<br />
Tutorial&quot; de Bruce Barnett que ilustra algo de esto y dejar&eacute; el tema<br />
all&iacute; mismo.</p>
<p>&nbsp;</p>
<p>
Lo que hace el ejemplo es guardar los p&aacute;rrafos en el &quot;hold buffer&quot; a<br />
medida que los va leyendo. Si el p&aacute;rrafo posee el patr&oacute;n pasado<br />
por par&aacute;metro al script lo imprime.</p>
<p>&nbsp;</p>
<pre>
#!/bin/sh
sed -n '
# Si es una l&iacute;nea vac&iacute;a, finaliza el p&aacute;rrafo.
# Por lo tanto se debe analizar. Se hace un &quot;GOTO&quot; a &quot;para&quot;.
/^$/ b para
# Si la l&iacute;nea no est&aacute; vac&iacute;a, se agrega al &quot;hold buffer&quot;.
H
# Al final del archivo se analiza el &uacute;ltimo p&aacute;rrafo.
# &quot;GOTO&quot; a &quot;para&quot;.
$ b para
# Se hace un &quot;GOTO&quot; al final del script.
b
# La etiqueta &quot;para&quot;. Secci&oacute;n donde se analiza el p&aacute;rrafo.
:para
# Se recupera el p&aacute;rrafo completo.
x
# Se busca el patr&oacute;n, si se encuetra se imprime el p&aacute;rrafo.
/'$1'/ p
'
</pre>
<p>&nbsp;</p>
<h2>6. Ap&eacute;ndice A: Quitando Tags XML. El Criterio &quot;The Longest Match&quot;</h2>
<p>&nbsp;</p>
<p>
Para mostrar c&oacute;mo se hace har&eacute; el siguiente ejercicio. Suponga<br />
el siguiente c&oacute;digo HTML:</p>
<p>&nbsp;</p>
<pre>
&lt;h2&gt;Contenido&lt;/h2&gt;
&lt;ul&gt;
&lt;li class=&quot;toclevel-1&quot;&gt;1 &lt;span class=&quot;toctext&quot;&gt;Historia&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;toclevel-1&quot;&gt;2 &lt;span class=&quot;toctext&quot;&gt;Ventajas del XML&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;toclevel-1&quot;&gt;3 &lt;span class=&quot;toctext&quot;&gt;Estructura del XML&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>&nbsp;</p>
<p>
Para obtener el texto sin los tags podr&iacute;a acceder a la p&aacute;gina<br />
ya procesada por el navegador web, copiar el texto con Ctrl-c y pegarlo con<br />
Ctrl-v en mi editor favorito (las teclas pueden cambiar seg&uacute;n el entorno<br />
en el que estemos trabajando). Pero aqu&iacute;, como mi intenci&oacute;n es<br />
mostrar el sed, lo har&eacute; con esta herramienta.</p>
<p>&nbsp;</p>
<p>
Lo que se me ocurre es sustituir el patr&oacute;n &quot;&lt;.*&gt;&quot;<br />
por una cadena vac&iacute;a. Sin embargo el resultado obtendido luego de<br />
ejecutar &quot;sed &#8216;s/&lt;.*&gt;//g&#8217; temp&quot; es varias l&iacute;neas<br />
vac&iacute;as.</p>
<p>&nbsp;</p>
<p>
Lo que pasa es que el patr&oacute;n es ambiguo. Por ejemplo para<br />
&quot;&lt;h2&gt;Contenido&lt;/h2&gt;&quot; sed comenzar&iacute;a leyendo desde<br />
el primer &quot;&lt;&quot;, pero podr&iacute;a detenerse en el &quot;&gt;&quot;<br />
detr&aacute;s del primer h2 o en el &quot;&gt;&quot; detr&aacute;s del segundo<br />
h2. Y los creadores de la herramienta han decidido que se tome siempre la<br />
coincidencia m&aacute;s larga, &quot;the longest match&quot;.</p>
<p>&nbsp;</p>
<p>
Una soluci&oacute;n al problema ser&iacute;a, por ejemplo, utilizar el<br />
patr&oacute;n &quot;&lt;[^&lt;]*&gt;&quot;. &quot;[^&lt;]&quot; significa<br />
cualquier caracter que no sea &quot;&lt;&quot;. En ese caso el resultado<br />
ser&iacute;a:</p>
<p>&nbsp;</p>
<pre>
Contenido
1 Historia
2 Ventajas del XML
3 Estructura del XML
</pre>
<p>&nbsp;</p>
<h2>7. Ap&eacute;ndice B: El Editor &quot;ed&quot;</h2>
<p>&nbsp;</p>
<p>
Los comandos del sed provienen del editor m&aacute;s primitivo de Unix, llamado<br />
&quot;ed&quot;. Este editor, a diferencia de sed que es un editor de flujo, es<br />
un editor com&uacute;n y corriente&#8230; bueno, casi. A diferencia de los editores<br />
modernos no es &quot;WYSIWYG&quot; (What You See Is What You Get, o &quot;lo que<br />
v&eacute;s es lo que obten&eacute;s&quot;), o sea que no nos muestra el texto<br />
que estamos editando, simplemente nos permite escribir comandos (m&aacute;s o<br />
menos los mismos que el sed) de manera interactiva.</p>
<p>&nbsp;</p>
<p>
El uso de este editor no es com&uacute;n en estos tiempos, ya que la<br />
mayor&iacute;a de los programadores y administradores de Unix prefieren trabajar<br />
con el &quot;vi&quot;. Sin embargo, el ed puede aprovecharse como otro comando<br />
para nuestros scripts cuando necesitamos abrir un archivo, hacer una<br />
edici&oacute;n y volver a grabarlo. En ese caso no precisamos un editor de<br />
flujo como el sed, sino m&aacute;s bien alguno que edite el archivo en el lugar.</p>
<p>&nbsp;</p>
<p>
Volvamos al ejemplo de eliminar los espacios sobrantes.</p>
<p>
</p>
<pre>
Aqu&iacute;   me pongo a   cantar
al  comp&aacute;s de    la vig&uuml;ela,
que al hombre  que lo desvela
una   pena     estrordinaria,
como la ave solitaria
con    el cantar se   consuela.
</pre>
<p>&nbsp;</p>
<p>
Imag&iacute;nese que el texto se encuentra en el archivo &quot;prueba.txt&quot;.<br />
Si lo resolvi&eacute;semos con el sed, como hicimos en el ejemplo pasado,<br />
obtendr&iacute;amos el resultado en la salida est&aacute;ndar o en otro archivo. Sin<br />
embargo queremos que los datos permanezcan en &quot;prueba.txt&quot; luego de la<br />
transformaci&oacute;n. Por lo que tenemos dos opciones: a) obtener los datos<br />
en un archivo auxiliar y luego reemplazar &quot;prueba.txt&quot; por este<br />
archivo; o b) editar el archivo en el lugar utilizando el &quot;ed&quot;.</p>
<p>&nbsp;</p>
<p>
El comando para editar el archivo en &quot;ed&quot; es el mismo que en el<br />
&quot;sed&quot; pero con tres salvedades. La primera es que &quot;ed&quot; no<br />
tiene como rango impl&iacute;cito todas las l&iacute;neas del archivo, por lo<br />
que s&iacute; o s&iacute; tenemos que indicarle el rango<br />
&quot;1,$&quot; delante del comando. La segunda es que luego de la<br />
transformaci&oacute;n debemos ejecutar el comando &quot;w&quot; para grabar<br />
el archivo, ya que &quot;ed&quot; no lo har&aacute; autom&aacute;ticamente.<br />
Y la tercera es que los comandos se separan con una nueva l&iacute;nea, y no<br />
con un &quot;;&quot;.</p>
<p>&nbsp;</p>
<p>
&quot;ed&quot; recibe el nombre del archivo como par&aacute;metro y lee los<br />
comandos desde la entrada est&aacute;ndar. Tambi&eacute;n requiere la<br />
opci&oacute;n &quot;-n&quot; para suprimir molestos mensajes. Por lo que<br />
quedar&iacute;a de la siguiente manera:</p>
<p>&nbsp;</p>
<pre>
ed -s prueba.txt &lt;&lt;&lt; $'1,$s/ \+/ /g\nw'
</pre>
<p>&nbsp;</p>
<p>
Pero algunas implementaciones modernas del &quot;sed&quot;, como por ejemplo la<br />
de GNU, tambi&eacute;n poseen la opci&oacute;n &quot;-i&quot; que permite<br />
modificar el archivo en el lugar y obtener el mismo resultado:</p>
<p>&nbsp;</p>
<pre>
sed -i 's/ \+/ /g' prueba.txt
</pre>
<p>&nbsp;</p>
<h2>8. Final</h2>
<p>&nbsp;</p>
<p>
&quot;sed&quot; se encuentra siempre entre mi reducido y selecto repertorio de<br />
herramientas de trabajo. Podr&iacute;a decir que est&aacute; entre las muy<br />
primeras opciones a la hora de realizar cualquier tipo de transformaci&oacute;n<br />
sobre textos extensos y que no conozco otra cosa que lo haga mejor.</p>
<p>&nbsp;</p>
<p>
Adem&aacute;s de eso he tenido la oportunidad de operar en varios sistemas<br />
tipo Unix distintos y todos poseen la herramienta. Y cuando me encontr&eacute;<br />
trabajando con sistemas de otro tipo, a falta de alguna mejor opci&oacute;n, he<br />
tenido la necesidad de instalarla. Dicho sea de paso, he conseguido<br />
implementaciones libres en la internet que se instalan f&aacute;cilmente y sin<br />
ning&uacute;n tipo de problema.</p>
<p>&nbsp;</p>
<p>
La herramienta es m&aacute;s bien compacta, sencilla y poderosa. Por lo que se<br />
logra dominar luego de usarla un par de veces, siempre y cuando se est&eacute;<br />
familiarizado con las expresiones regulares. Y si no lo est&aacute; es muy<br />
recomendable que lea alg&uacute;n tutorial peque&ntilde;o sobre el asunto y lo<br />
ponga en pr&aacute;ctica.</p>
<p>&nbsp;</p>
<p>
Hasta aqu&iacute; espero que haya obtenido una idea acerca del &quot;sed&quot; y<br />
del provecho que le puede sacar tanto para crear scripts o para transformar<br />
todo tipo de textos.</p>
<p>
</p>
<p>Para m&aacute;s informaci&oacute;n sugiero que lea la documentaci&oacute;n de</p>
<p>&nbsp;</p>
<p>la implementaci&oacute;n en su sistema operativo. Si tiene GNU instalado</p>
<p>&nbsp;</p>
<p>escriba &quot;info sed&quot;. Tambi&eacute;n encontrar&aacute; muchos textos</p>
<p>&nbsp;</p>
<p>escritos en todos los idiomas en la internet, lo que es un punto a favor</p>
<p>&nbsp;</p>
<p>del uso del &quot;sed&quot;.</p>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2009/10/mas-cosas-guays-sobre-el-comando-sed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Aplicaciones IPHONE</title>
		<link>http://smultron.es/2009/09/aplicaciones-iphone/</link>
		<comments>http://smultron.es/2009/09/aplicaciones-iphone/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 20:31:43 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[crear]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4519</guid>
		<description><![CDATA[En este documento encontrareis la metodolog&#237;a y experiencia adecuada para desarrollar vuestras propias aplicaciones de iphone. &#160;&#160; Ampliar ENLACE: http://bitelia.com/2009/02/como-crear-una-aplicacion-para-iphone-en-30-dias Enlace Oficial: http://developer.apple.com/iphone/designingcontent.html]]></description>
			<content:encoded><![CDATA[<p>En este documento encontrareis la metodolog&iacute;a y experiencia adecuada para desarrollar vuestras propias aplicaciones de iphone.</p>
<p>&nbsp;<object width="100%" height="500" align="middle" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="doc_483342261362758" name="doc_483342261362758" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param name="movie" value="http://d.scribd.com/ScribdViewer.swf?document_id=12684298&amp;access_key=key-c0uc3wjw8uao8poe0k4&amp;page=1&amp;version=1&amp;viewMode=" /><param name="quality" value="high" /><param name="play" value="true" /><param name="loop" value="true" /><param name="scale" value="showall" /><param name="wmode" value="opaque" /><param name="devicefont" value="false" /><param name="bgcolor" value="#ffffff" /><param name="menu" value="true" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="salign" value="" /><embed width="100%" height="500" align="middle" src="http://d.scribd.com/ScribdViewer.swf?document_id=12684298&amp;access_key=key-c0uc3wjw8uao8poe0k4&amp;page=1&amp;version=1&amp;viewMode=" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" play="true" loop="true" scale="showall" wmode="opaque" devicefont="false" bgcolor="#ffffff" name="doc_483342261362758_object" menu="true" allowfullscreen="true" allowscriptaccess="always" salign="" type="application/x-shockwave-flash"></embed></object>&nbsp;</p>
<p><a alt="PDF" rel="PDF[Manual Smultron]" author="Crea Tu Aplicaci&oacute;n" title="Manual IPHONE" class="lightwindow" href="http://d.scribd.com/ScribdViewer.swf?document_id=12684298&amp;access_key=key-c0uc3wjw8uao8poe0k4&amp;page=1&amp;version=1&amp;viewMode=">Ampliar</a></p>
<p>ENLACE: http://bitelia.com/2009/02/como-crear-una-aplicacion-para-iphone-en-30-dias</p>
<p>Enlace Oficial: http://developer.apple.com/iphone/designingcontent.html</p>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2009/09/aplicaciones-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Claves por defecto</title>
		<link>http://smultron.es/2009/09/claves-por-defecto/</link>
		<comments>http://smultron.es/2009/09/claves-por-defecto/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 20:50:00 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4485</guid>
		<description><![CDATA[Copy&#38;Page:http://www.phenoelit-us.org/dpl/dpl.html Default Password List Last updated: 09.15.2009 Vendor Model Version Access Type Username Password Privileges Notes 3COM CoreBuilder 7000/6000/3500/2500 Telnet debug synnet &#160; &#160; 3COM CoreBuilder 7000/6000/3500/2500 Telnet tech tech &#160; &#160; 3COM HiPerARC v4.1.x Telnet adm (none) &#160; &#160; 3COM LANplex 2500 Telnet debug synnet &#160; &#160; 3COM LANplex 2500 Telnet tech tech &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Copy&amp;Page:<span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><a href="http://www.phenoelit-us.org/dpl/dpl.html">http://www.phenoelit-us.org/dpl/dpl.html</a></span></p>
<p><span id="more-4485"></span></p>
<p><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; "></p>
<div style="background-color: rgb(0, 0, 0); color: rgb(255, 153, 0); ">
<h1 align="center">Default Password List</h1>
<h2 align="center">Last updated: 09.15.2009</h2>
<p></p>
<table id="result" style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: solid; border-right-style: none; border-bottom-style: solid; border-left-style: none; border-width: initial; border-color: initial; border-top-width: thin; border-top-color: rgb(34, 34, 34); border-bottom-width: thin; border-bottom-color: rgb(34, 34, 34); ">
<tbody>
<tr>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><b style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Vendor</b></td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><b style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Model</b></td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><b style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Version</b></td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><b style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Access Type</b></td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><b style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Username</b></td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><b style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Password</b></td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><b style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Privileges</b></td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><b style="font-size: 12px; line-height: 14px; font-family: Helvetica, Arial; color: rgb(255, 153, 0); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Notes</b></td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CoreBuilder</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000/6000/3500/2500</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">debug</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">synnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CoreBuilder</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000/6000/3500/2500</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">HiPerARC</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">v4.1.x</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">adm</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">LANplex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">2500</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">debug</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">synnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">LANplex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">2500</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">LinkSwitch</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">2000/2700</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">NetBuilder</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SNMP</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">ANYCOM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">snmp-read</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">NetBuilder</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SNMP</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">ILMI</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">snmp-read</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Netbuilder</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Office Connect ISDN Routers</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">5&#215;0</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">n/a</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">PASSWORD</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SuperStack II Switch</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">2200</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">debug</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">synnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SuperStack II Switch</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">2700</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">OfficeConnect 812 ADSL</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">adminttd</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">adminttd</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Wireless AP</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">ANY</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">comcomcom</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Works on all 3com wireless APs</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CellPlex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">User</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">cellplex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">cellplex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">operator</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">HiPerARC</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">v4.1.x</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">adm</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3Com SuperStack 3 Switch 3300XM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">security</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">security</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">superstack II</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">1100/3300</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Console</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3comcso</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">RIP000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">initialize</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">resets all pws to defaults</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">LANplex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">2500</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CellPlex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">HTTP</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">synnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">NetBuilder</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SNMP</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">User</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SNMP_READ</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SuperStack II Switch</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">2700</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CellPlex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">root</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">HiPerACT</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">v4.1.x</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CellPlex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CellPlex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CellPlex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">tech</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">super</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">cellplex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">RS-232/telnet</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SuperStack 3</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">4XXX</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SuperStack 3</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">4XXX</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">monitor</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">monitor</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">User</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SuperStack 3</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">4400-49XX</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">manager</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">manager</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">User can access/change operational setting but not security settings</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">CellPlex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">root</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Netbuilder</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">cellplex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">7000</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">operator</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">OfficeConnect 812 ADSL</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">01.50-01</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">cellplex</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">HiPerACT</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">v4.1.x</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3c16405</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">n/a</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3c16405</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Console</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Administrator</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Switch</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3300XM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">SS III Switch</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">4xxx (4900 &#8211; sure)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Telnet</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">recovery</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">recovery</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">resets_all_to_default</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">u need to power off unit. tbl_</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">OfficeConnect Wireless 11g Cable/DSL Gateway</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">HTTP</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
</tr>
<tr style="background-color: rgb(0, 0, 0); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3COM</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Netbuilder</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">HTTP</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Root</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">http://10.1.0.1</td>
</tr>
<tr style="background-color: rgb(34, 34, 34); ">
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3com</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">3C16405</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">Multi</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">admin</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">(none)</td>
<td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-wi</p>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2009/09/claves-por-defecto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expresiones regulares para VIM</title>
		<link>http://smultron.es/2009/09/expresiones-regulares-para-vim/</link>
		<comments>http://smultron.es/2009/09/expresiones-regulares-para-vim/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 16:49:22 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4483</guid>
		<description><![CDATA[&#160; Copy&#38;Page:http://www.geocities.com/volontir/ &#160; &#169; WebRing Inc. The Vi IMproved Editor Web Ring &#60;&#60; Prev &#124; Ring Hub &#124; Join &#124; Rate&#124; Next &#62;&#62; &#160; &#60;center&#62; &#60;table width=&#34;75%&#34; cellpadding=2 cellspacing=0&#62; &#60;tr valign=bottom&#62;&#60;td&#62; &#60;table bgcolor=990066 border=0 width=&#34;75%&#34;&#62;&#60;tr&#62;&#60;td&#62; &#60;table bgcolor=eeeeee cellpadding=6 cellspacing=0 border=0 width=&#34;100%&#34;&#62;&#60;tr&#62;&#60;td align=center&#62; &#60;font face=arial size=-1&#62;This site is a member of WebRing. To browse visit&#60;/font&#62;&#60;br&#62;&#60;font face=arial [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Copy&amp;Page:http://www.geocities.com/volontir/</p>
<p><span id="more-4483"></span></p>
<table border="0" width="636">
<tbody>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
            <script src="http://ss.webring.com/navbar?f=j&amp;y=oleg66&amp;u=10002161" language="javascript" type="text/javascript">
</script></p>
<table cellspacing="0" cellpadding="0" border="0" align="center" width="160">
<tbody>
<tr>
<td><center><!--vim--><br />
<style type="text/css"><!--.st1 {color: blue;}.st2 {color: black; text-decoration: none;}--></style>
<table cellspacing="0" cellpadding="2" bordercolor="#990066" border="1" width="470">
<tbody>
<tr>
<td nowrap="nowrap">
<table cellspacing="0" cellpadding="1" border="0" bgcolor="#eeeeee" width="470">
<tbody>
<tr>
<td nowrap="nowrap" width="1%"><a target="_top" href="http://u.webring.com/t/The-Vi-IMproved-Editor-Web-Ring?sid=8"><img height="50" border="0" width="35" alt="The Vi IMproved Editor Web Ring" src="http://mywebpage.netscape.com/pottsdl1/gifs/vim_gindikin_vim_on_fire.gif" /></a><font face="arial" size="-2"><br />
                                                <span class="st2">&copy; </span><a href="http://www.webring.com/"><span class="st1">WebRing Inc.</span></a></font></td>
<td nowrap="nowrap">
<table cellspacing="2" cellpadding="0" border="0" width="100%">
<tbody>
<tr>
<td nowrap="nowrap"><a target="_top" href="http://u.webring.com/t/The-Vi-IMproved-Editor-Web-Ring?sid=8"><span class="st2"><b>The Vi IMproved Editor Web Ring</b></span></a></td>
</tr>
<tr>
<td nowrap="nowrap" colspan="2"><span class="st2"><b><a title="visit previous site in The Vi IMproved Editor Web Ring" target="_top" href="http://u.webring.com/go?ring=vim;sid=8;id=8;prev"><span class="st1">&lt;&lt; Prev</span></a></b> | <a target="_top" href="http://u.webring.com/t/The-Vi-IMproved-Editor-Web-Ring?sid=8"><span title="visit The Vi IMproved Editor Web Ring community pages" class="st1">Ring Hub</span></a> | <a title="join The Vi IMproved Editor Web Ring communiy" target="_top" href="http://u.webring.com/wrman?ring=vim;sid=8;addsite"><span class="st1">Join</span></a> | <b><a title="Rate this site" target="_top" href="http://u.webring.com/go?ring=vim;sid=8;id=8;prvw"><span class="st1">Rate</span></a></b>| <b><a title="go to next site in The Vi IMproved Editor Web Ring" target="_top" href="http://u.webring.com/go?ring=vim;sid=8;id=8;next"><span class="st1">Next &gt;&gt;</span></a></b> </span></td>
</tr>
<tr>
<form action="http://U.webring.com/cgi-bin/Hubsearch?ringsearch" method="post">
                                                                &nbsp;<br />
                                                            </form>
<td nowrap="nowrap" colspan="2">
<input type="text" style="height: 19px;" size="18" name="query" />
<input type="submit" style="height: 19px;" value="Search" name="Submit" />
<input type="hidden" value="vim" name="ring" /></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>                        </center></td>
</tr>
</tbody>
</table>
<p>            <noscript>&lt;center&gt; &lt;table width=&quot;75%&quot; cellpadding=2 cellspacing=0&gt; &lt;tr valign=bottom&gt;&lt;td&gt; &lt;table bgcolor=990066 border=0 width=&quot;75%&quot;&gt;&lt;tr&gt;&lt;td&gt; &lt;table bgcolor=eeeeee cellpadding=6 cellspacing=0 border=0 width=&quot;100%&quot;&gt;&lt;tr&gt;&lt;td align=center&gt; &lt;font face=arial size=-1&gt;This site is a member of WebRing.  To browse visit&lt;/font&gt;&lt;br&gt;&lt;font face=arial size=-2&gt; &lt;a href=&quot;http://ss.webring.com/navbar?f=l&amp;y=oleg66&amp;u=10002161&quot;&gt; http://ss.webring.com/navbar?f=l&amp;y=oleg66&amp;u=10002161 &lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/center&gt;</noscript></td>
</tr>
<tr>
<td class="title" colspan="3"><img height="75" width="524" src="http://www.geocities.com/volontir/images/regex-title.gif" alt="" /></td>
</tr>
<tr>
<td class="title" colspan="3">
<table height="20" cellspacing="2" cellpadding="2" border="0" width="556" class="buttonbar">
<tbody>
<tr>
<td><a href="http://www.geocities.com/volontir/#news">news</a></td>
<td>
<ul>
<li><a href="http://www.geocities.com/volontir/#intro">&nbsp;intro</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="http://www.geocities.com/volontir/#substitute">&nbsp;substitute</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="http://www.geocities.com/volontir/#global">&nbsp;global</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="http://www.geocities.com/volontir/#pattern">&nbsp;patterns</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="http://www.geocities.com/volontir/#examples">&nbsp;examples</a></li>
</ul>
</td>
<td nowrap="nowrap">
<ul>
<li><a href="http://www.geocities.com/volontir/#compare">other flavors</a></li>
</ul>
</td>
<td>
<ul>
<li>&nbsp;<a href="http://www.geocities.com/volontir/#links">links</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">
<h1>Contents</h1>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<p><a class="majorhead" href="http://www.geocities.com/volontir/#news">I. News</a><br />
            <a class="majorhead" href="http://www.geocities.com/volontir/#intro">II. Introduction</a><br />
            <a href="http://www.geocities.com/volontir/#whatisvim" class="minorhead">2.1 What is VIM?</a><br />
            <a href="http://www.geocities.com/volontir/#about" class="minorhead">2.2 About this Tutorial</a><br />
            <a href="http://www.geocities.com/volontir/#credits" class="minorhead">2.3 Credits</a><br />
            <a class="majorhead" href="http://www.geocities.com/volontir/#substitute">III. Substitute Command</a><br />
            <a href="http://www.geocities.com/volontir/#substitute" class="minorhead">3.1 Search &amp; Replace</a><br />
            <a href="http://www.geocities.com/volontir/#address" class="minorhead">3.2 Line Ranges &amp; Addressing</a><br />
            <a class="majorhead" href="http://www.geocities.com/volontir/#pattern">IV. Pattern Description </a><br />
            <a href="http://www.geocities.com/volontir/#anchors" class="minorhead">4.1 Anchors</a><br />
            <a href="http://www.geocities.com/volontir/#metacharacters" class="minorhead">4.2 &quot;Escaped&quot; characters          or metacharacters</a><br />
            <a href="http://www.geocities.com/volontir/#Non-Greedy" class="minorhead">4.3 Quantifiers, Greedy and Non-Greedy</a><br />
            <a href="http://www.geocities.com/volontir/#ranges" class="minorhead">4.4 Character ranges</a><br />
            <a href="http://www.geocities.com/volontir/#backreferences" class="minorhead">4.5 Grouping and Backreferences</a><br />
            <a href="http://www.geocities.com/volontir/#alternations" class="minorhead">4.6 Alternations</a><br />
            <a href="http://www.geocities.com/volontir/#precedence" class="minorhead">4.7 Operator Precedence</a><br />
            <a class="majorhead" href="http://www.geocities.com/volontir/#global">V. Global Command</a><br />
            <a href="http://www.geocities.com/volontir/#global%20search" class="minorhead">5.1 Global search and execution</a><br />
            <a href="http://www.geocities.com/volontir/#global%20examples" class="minorhead">5.2 Examples</a><br />
            <a class="majorhead" href="http://www.geocities.com/volontir/#examples">VI. Examples</a><br />
            <a href="http://www.geocities.com/volontir/#tips" class="minorhead">6.1 Tips &amp; Techniques</a><br />
            <a href="http://www.geocities.com/volontir/#contents" class="minorhead">6.2 Creating Outline</a><br />
            <a href="http://www.geocities.com/volontir/#tables" class="minorhead">6.3 Working with Tables</a><br />
            <a class="majorhead" href="http://www.geocities.com/volontir/#compare">VII. Other Regexp Flavors</a><br />
            <a class="majorhead" href="http://www.geocities.com/volontir/#links">VIII. Links</a></p>
</td>
</tr>
<tr>
<td colspan="3">
<h1><a name="news">I. News</a></h1>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">
<ul>
<li>Finally, I&#8217;ve moved this page from City College&#8217;s physlab server,            which is no longer maintained.</li>
<li>VIM 6.0 is now official. A lot of changes and new features were introduced.            I&#8217;ll try to bring this page in a line with the current VIM version.</li>
<li>I no longer support the VIM reference guide. <a href="mailto:sheffner@web.de"><b>Stephan            Heffner</b></a> has voluntereed to update the guide.</li>
</ul>
</td>
</tr>
<tr>
<td colspan="3">
<h1><a name="intro">II. Introduction</a></h1>
</td>
</tr>
<tr>
<td colspan="3">
<h2><a name="whatisvim">2.1 What is VIM?</a></h2>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">
<p>Vim is an improved (in many ways) version of vi, a ubiquitous text editor          found on any UNIX system. VIM was created by <a href="http://www.geocities.com/volontir/images/photos/nyc/pics/linux-bram.jpg">Bram          Moolenaar</a> with a help of other people. It&#8217;s free but if you like it          you can make a charitable contribution to orphans in Uganda.</p>
<p>Vim has its own web site, <a href="http://www.vim.org/"><b>www.vim.org</b></a>          and several <a href="http://www.vim.org/mail.html">mailing lists</a>,          with a wealth of information on every aspect of VIM. Vim was successfully          ported to nearly all existing OS. It is a default editor in many Linux          distributions (e.g. RedHat).</p>
<p>VIM has all features of a modern programmer&#8217;s editor &#8211; macro language,          syntax highlighting, customizable user interface, easy integration with          various IDEs plus a set of features which makes VIM so attractive to its          users: crash recovery, automatic commands, session management.</p>
<p>VIM has a very broad and loyal user base. Over 10 million people have          it installed (counting only Linux users). Estimation is that there are          about half a million people using Vim as their main editor. And this number          is growing.</p>
</td>
</tr>
<tr>
<td colspan="3">
<h2><a name="about">2.2 About this Tutorial</a></h2>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<p>I started this tutorial for one simple reason &#8211; I like regular expressions.          Nothing compares to the satisfaction from a well-crafted regexp which          does exactly what you wanted it to do :-). I hope it&#8217;s passable as a foreword.</p>
<p>Speaking more seriously, regular expressions (or regexps for short) are          tools used to manipulate text and data. They don&#8217;t exist as a standalone          product but usually are a part of some program/utility. The best known          example is UNIX<i> grep, </i>a program to search files for lines that          match certain pattern. The search pattern is described in terms of <i>regular          expressions. </i>You can think of regexps as a specialized pattern language.          Regexps are quite useful and can greatly reduce time it takes to do some          tedious text editing.</p>
<p>(Regexp terminology is largely borrowed from Jeffrey Friedl &quot;Mastering          Regular Expressions.&quot;)</p>
</td>
</tr>
<tr>
<td colspan="3">
<h2><a name="credits">2.3 Credits</a></h2>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">
<p>Many thanks (in no particular order): Benji Fisher, Zdenek Sekera, Preben          &quot;Peppe&quot; Guldberg, Steve Kirkendall, Shaul Karl and all others          who helped me with their comments.</p>
<p>Feel free to send me (<a href="mailto:volontir%20at%20yahoo%20dot%20com"><img border="0" align="absbottom" src="http://www.geocities.com/volontir/images/email.gif" alt="" /></a><b>volontir          at yahoo dot com</b>) your comments. suggestions, examples&#8230;</p>
</td>
</tr>
<tr>
<td colspan="3">
<h1><a name="substitute">III. Substitute Command</a></h1>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="replace">3.1 Search &amp; Replace</a></h2>
<p>So, what can you do with regular expressions? The most common task is          to make replacements in a text following some certain rules. For this          tutorial you need to know VIM search and replace command (S&amp;R) <code>:substitute</code>.          Here is an excerpt from VIM help:</p>
<table cellspacing="3" class="vimdoc">
<tbody>
<tr>
<td colspan="2"><b>:<i>range</i> s[ubstitute]/<i>pattern</i>/<i>string</i>/cgiI</b></td>
</tr>
<tr>
<td colspan="2">For each line in<b> <i>the range</i></b> replace a match              of <i><b>the pattern</b></i> with <i><b>the string</b></i> where:</td>
</tr>
<tr>
<td width="44">
<div align="center"><b>c</b></div>
</td>
<td width="551">Confirm each substitution</td>
</tr>
<tr>
<td width="44">
<div align="center"><b>g</b></div>
</td>
<td width="551">Replace all occurrences in the line (without <b>g </b>-              only first).</td>
</tr>
<tr>
<td width="44">
<div align="center"><b>i</b></div>
</td>
<td height="19" width="551">Ignore case for the pattern.</td>
</tr>
<tr>
<td width="44">
<div align="center"><b>I </b></div>
</td>
<td width="551">Don&#8217;t ignore case for the pattern.</td>
</tr>
</tbody>
</table>
<p>Part of the command word enclosed in the &quot;[&quot; &amp; &quot;]&quot;          can be omitted.</p>
<h2><a name="address">3.2 Range of Operation, Line Addressing and Marks</a></h2>
<p>Before I begin with a pattern description let&#8217;s talk about line addresses          in Vim. Some Vim commands can accept a line range in front of them. By          specifying the line range you restrict the command execution to this particular          part of text only. Line range consists of one or more line specifiers,          separated with a comma or semicolon. You can also mark your current position          in the text typing <code>m<i>l</i></code> , where <i>&quot;l&quot;</i>          can be any letter, and use it later defining the line address.</p>
<table cellspacing="3" width="585" class="vimdoc">
<tbody>
<tr>
<td>
<div align="center"><b>Specifier</b></div>
</td>
<td>
<div align="center"><b>Description</b></div>
</td>
</tr>
<tr>
<td>
<div align="center"><b><i>number</i></b></div>
</td>
<td>an absolute line number</td>
</tr>
<tr>
<td>
<div align="center"><b>. </b></div>
</td>
<td>the current line</td>
</tr>
<tr>
<td>
<div align="center"><b>$</b></div>
</td>
<td>the last line in the file</td>
</tr>
<tr>
<td>
<div align="center"><b>%</b></div>
</td>
<td>the whole file. The same as <b>1,$</b></td>
</tr>
<tr>
<td>
<div align="center"><b>&#8216;<i>t </i></b></div>
</td>
<td>position of mark &quot;t&quot;</td>
</tr>
<tr>
<td>
<div align="center"><b>/<i>pattern</i>[/]</b></div>
</td>
<td>the next line where text<i> &quot;pattern</i>&quot; matches.</td>
</tr>
<tr>
<td>
<div align="center"><b> ?<i>pattern</i>[?] </b></div>
</td>
<td>the previous line where text &quot;<i>pattern</i>&quot; matches</td>
</tr>
<tr>
<td>
<div align="center"><b>\/ </b></div>
</td>
<td>the next line where the previously used search pattern matches</td>
</tr>
<tr>
<td>
<div align="center"><b>\?</b></div>
</td>
<td>the previous line where the previously used search pattern matches</td>
</tr>
<tr>
<td>
<div align="center"><b>\&amp;</b></div>
</td>
<td>the next line where the previously used substitute pattern matches</td>
</tr>
</tbody>
</table>
<p>If no line range is specified the command will operate on the current          line only.</p>
<p>Here are a few examples:</p>
<p><code>10,20 </code></p>
<p>- from 10 to 20 line.</p>
<p>Each may be followed (several times) by &quot;+&quot; or &quot;-&quot;          and an optional number. This number is added or subtracted from the preceding          line number. If the number is omitted, 1 is used.</p>
<p class="pattern"><code>/Section 1/+,/Section 2/-</code></p>
<p>- all lines between <span class="pattern">Section 1</span> and <span class="pattern">Section          2</span>, non-inclusively, i.e. the lines containing <span class="pattern">Section          1</span> and <span class="pattern">Section 2</span> will not be affected.</p>
<p>The <code>/<i>pattern</i>/</code> and <code>?<i>pattern</i>?</code> may          be followed by another address separated by a semicolon. A semicolon between          two search patterns tells Vim to find the location of the first pattern,          then start searching from that location for the second pattern.</p>
<p><code>/Section 1/;/Subsection/-,/Subsection/+</code></p>
<p>- first find <span class="pattern">Section 1</span>, then the first line          with <span class="pattern">Subsection</span>, step one line down (beginning          of the range) and find the next line with <span class="pattern">Subsection</span>,          step one line up (end of the range).</p>
<p>The next example shows how you can reuse you search pattern:</p>
<p><code>:/Section/+ y</code></p>
<p>- this will search for the <span class="pattern">Section</span> line          and yank (copy) one line after into the memory.</p>
<p><code>:// normal p</code></p>
<p>- and that will search for the next <span class="pattern">Section</span>          line and put (paste) the saved text on the next line.</p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<div class="tip">
<p><b>Tip 1:</b> frequently you need to do S&amp;R in a text which contains            UNIX file paths &#8211; text strings with slashes (&quot;/&quot;) inside.            Because S&amp;R command uses slashes for pattern/replacement separation            you have to escape every slash in your pattern, i.e. use &quot;\/&quot;            for every &quot;/&quot; in your pattern:</p>
<p><code>s/\/dir1\/dir2\/dir3\/file/dir4\/dir5\/file2/g</code></p>
<p>To avoid this so-called &quot;backslashitis&quot; you can use different            separators in S&amp;R (I prefer &quot;:&quot;)</p>
<p><code>s:/dir1/dir2/dir3/file:/dir4/dir5/file2:g</code></p>
<p><b>Tip 2:</b> You may find these mappings useful (put them in your            <b>.vimrc</b> file)</p>
<p><code>noremap ;; :%s:::g&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;<br />
            noremap ;' :%s:::cg&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;</code></p>
<p>These mappings save you some keystrokes and put you where you start            typing your search pattern. After typing it you move to the replacement            part , type it and hit return. The second version adds confirmation            flag.</p>
</p></div>
</td>
</tr>
<tr>
<td colspan="3">
<h1><a name="pattern">IV. Pattern Description</a></h1>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="anchors">4.1 Anchors</a></h2>
<p>Suppose you want to replace all occurrences of <span class="pattern">vi</span>          with <span class="pattern">VIM</span>. This can be easily done with</p>
<p><code>s/vi/VIM/g</code></p>
<p>If you&#8217;ve tried this example then you, no doubt, noticed that <span class="pattern">VIM</span>          replaced all occurrences of <span class="pattern">vi</span> even if it&#8217;s          a part of the word (e.g. na<span class="match">vi</span>gator). If we          want to be more specific and replace only whole words <span class="pattern">vi</span>          then we need to correct our pattern. We may rewrite it by putting spaces          around <span class="pattern">vi</span>:</p>
<p><code>s: vi : VIM :g</code></p>
<p>But it will still miss <span class="pattern">vi</span> followed by the          punctuation or at the end of the line/file. The right way is to put special          word boundary symbols &quot;<code>\&lt;</code>&quot; and &quot;<code>\&gt;</code>&quot;          around <span class="pattern">vi</span>.</p>
<p><code>s:\&lt;vi\&gt;:VIM:g</code></p>
<p>The beginning and the end of the line have their own special anchors          &#8211; &quot;<code>^</code>&quot; and &quot;<code>$</code>&quot;, respectively.          So, for all <span class="pattern">vi</span> only at the start of the line:</p>
<p><code>s:^vi\&gt;:VIM:</code></p>
<p>To match the lines where <span class="pattern">vi</span> is the only          word:</p>
<p><code>s:^vi$:VIM:</code></p>
<p>Now suppose you want to replace not only all <span class="pattern">vi</span>          but also <span class="pattern">Vi</span> and <span class="pattern">VI</span>.          There are several ways to do this:</p>
<ul>
<li>probably the simplest way is to put &quot;i&quot; &#8211; ignore case in            a pattern <code>%s:vi:VIM:gi</code></li>
<li>define a class of characters. This is a sequence of characters enclosed            by square brackets &quot;[&quot; and &quot;]&quot;. It matches any character            from this set. So <code>:%s:[Vv]i:VIM:</code> will match <span class="pattern">vi</span>            and <span class="pattern">Vi</span>. More on character ranges in the            following <a href="http://www.geocities.com/volontir/#ranges">section</a>.</li>
</ul>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="metacharacters">4.2 &quot;Escaped&quot; characters or metacharacters</a></h2>
<p>So far our pattern strings were constructed from normal or <i><b>literal          </b></i>text characters. The power of regexps is in the use of <i><b>metacharacters</b>.          </i>These are types of characters which have special meaning inside the          search pattern. With a few exceptions these metacharacters are distinguished          by a &quot;magic&quot; backslash in front of them. The table below lists          some common VIM metacharacters.</p>
<table cellspacing="3" class="vimdoc">
<tbody>
<tr>
<th width="43">
<div align="center"><b>#</b></div>
</th>
<th width="245">
<div align="center"><b>Matching</b></div>
</th>
<th width="46">
<div align="center"><b>#</b></div>
</th>
<th width="225">
<div align="center"><b>Matching</b></div>
</th>
</tr>
<tr>
<td width="43">
<div align="center"><b>.</b></div>
</td>
<td width="245">any character except new line</td>
<td width="46">&nbsp;</td>
<td width="225">&nbsp;</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\s</b></div>
</td>
<td width="245">whitespace character</td>
<td width="46">
<div align="center"><b>\S</b></div>
</td>
<td width="225">non-whitespace character</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\d</b></div>
</td>
<td width="245">digit</td>
<td width="46">
<div align="center"><b>\D</b></div>
</td>
<td width="225">non-digit</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\x</b></div>
</td>
<td width="245">hex digit</td>
<td width="46">
<div align="center"><b>\X</b></div>
</td>
<td width="225">non-hex digit</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\o</b></div>
</td>
<td width="245">octal digit</td>
<td width="46">
<div align="center"><b>\O</b></div>
</td>
<td width="225">non-octal digit</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\h</b></div>
</td>
<td width="245">head of word character (a,b,c&#8230;z,A,B,C&#8230;Z and _)</td>
<td width="46">
<div align="center"><b>\H</b></div>
</td>
<td width="225">non-head of word character</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\p</b></div>
</td>
<td width="245">printable character</td>
<td width="46">
<div align="center"><b>\P</b></div>
</td>
<td width="225">like <b>\p</b>, but excluding digits</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\w</b></div>
</td>
<td width="245">word character</td>
<td width="46">
<div align="center"><b>\W</b></div>
</td>
<td width="225">non-word character</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\a</b></div>
</td>
<td width="245">alphabetic character</td>
<td width="46">
<div align="center"><b>\A</b></div>
</td>
<td width="225">non-alphabetic character</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\l</b></div>
</td>
<td width="245">lowercase character</td>
<td width="46">
<div align="center"><b>\L</b></div>
</td>
<td width="225">non-lowercase character</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\u</b></div>
</td>
<td width="245">uppercase character</td>
<td width="46">
<div align="center"><b>\U</b></div>
</td>
<td width="225">non-uppercase character</td>
</tr>
</tbody>
</table>
<p>So, to match a date like 09/01/2000 you can use (assuming you don&#8217;t use          &quot;/&quot; as a separator in the S&amp;R)<code> </code></p>
<p><code>\d\d/\d\d/\d\d\d\d</code></p>
<p>To match 6 letter word starting with a capital letter</p>
<p><code>\u\w\w\w\w\w</code></p>
<p>Obviously, it is not very convenient to write <code>\w</code> for any          character in the pattern &#8211; what if you don&#8217;t know how many letters in          your word? This can be helped by introducing so-called <i>quantifiers</i>.</p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="Non-Greedy">4.3 Quantifiers, Greedy and Non-Greedy</a></h2>
<p>Using quantifiers you can set how many times certain part of you pattern          should repeat by putting the following after your pattern:</p>
<table cellspacing="3" width="585" class="vimdoc">
<tbody>
<tr>
<th>
<div align="center"><b>Quantifier</b></div>
</th>
<th>
<div align="center"><b>Description</b></div>
</th>
</tr>
<tr>
<td>
<div align="center"><b>*</b></div>
</td>
<td>matches 0 or more of the preceding characters, ranges or metacharacters              .* matches everything including empty line</td>
</tr>
<tr>
<td>
<div align="center"><b>\+</b></div>
</td>
<td>matches 1 or more of the preceding characters&#8230;</td>
</tr>
<tr>
<td>
<div align="center"><b>\= </b></div>
</td>
<td>matches 0 or 1 more of the preceding characters&#8230;</td>
</tr>
<tr>
<td>
<div align="center"><b>\{n,m}</b></div>
</td>
<td>matches from n to m of the preceding characters&#8230;</td>
</tr>
<tr>
<td>
<div align="center"><b>\{n}</b></div>
</td>
<td>matches exactly n times of the preceding characters&#8230;</td>
</tr>
<tr>
<td>
<div align="center"><b>\{,m}</b></div>
</td>
<td>matches at most m (from 0 to m) of the preceding characters&#8230;</td>
</tr>
<tr>
<td>
<div align="center"><b>\{n,}</b></div>
</td>
<td>matches at least n of of the preceding characters&#8230;</td>
</tr>
<tr>
<td colspan="2">
<div align="center">where <b>n</b> and <b>m</b> are positive integers                (&gt;0)</div>
</td>
</tr>
</tbody>
</table>
<p>Now it&#8217;s much easier to define a pattern that matches a word of <i>any          </i> length <code>\u\w\+</code>.</p>
<p>These quantifiers are <i>greedy</i> &#8211; that is your pattern will try to          match <i> <b>as much text as</b></i> possible. Sometimes it presents a          problem. Let&#8217;s consider a typical example &#8211; define a pattern to match          delimited text, i.e. text enclosed in quotes, brackets, etc. Since we          don&#8217;t know what kind of text is inside the quotes we&#8217;ll use</p>
<p><code>/&quot;.*&quot;/</code></p>
<p>But this pattern will match <i>everything</i> between the first &quot;          and the last &quot; in the following line:</p>
<p><code>this file is normally <span class="match">&quot;$VIM/.gvimrc&quot;. You          can check this with &quot;:version&quot;</span>.</code></p>
<p>This problem can be resolved by using non-greedy quantifiers:</p>
<table cellspacing="3" width="585" class="vimdoc">
<tbody>
<tr>
<td>
<div align="center"><b>Quantifier</b></div>
</td>
<td>
<div align="center"><b>Description</b></div>
</td>
</tr>
<tr>
<td>
<div align="center"><b>\{-}</b></div>
</td>
<td>matches 0 or more of the preceding atom, as few as possible</td>
</tr>
<tr>
<td>
<div align="center"><b>\{-n,m} </b></div>
</td>
<td>matches 1 or more of the preceding characters&#8230;</td>
</tr>
<tr>
<td>
<div align="center"><b>\{-n,}</b></div>
</td>
<td>matches at lease or more of the preceding characters&#8230;</td>
</tr>
<tr>
<td>
<div align="center"><b>\{-,m} </b></div>
</td>
<td>matches 1 or more of the preceding characters&#8230;</td>
</tr>
<tr>
<td colspan="2">
<div align="center">where <b>n</b> and <b>m</b> are positive integers                (&gt;0)</div>
</td>
</tr>
</tbody>
</table>
<p>Let&#8217;s use <code>\{-}</code> in place of <code>*</code> in our pattern.          So, now <code>&quot;.\{-}&quot;</code> will match the first quoted text:</p>
<p><code>this file is normally <span class="match">&quot;$VIM/gvimrc&quot;</span>.          You can check this with &quot;:version&quot;.</code></p>
<p><code>.\{-}</code> pattern is not without surprises. Look what will happen          to the following text after we apply:</p>
<p><code>:s:.\{-}:_:g</code></p>
<p>Before:</p>
<p><code>n and m are decimal numbers between</code></p>
<p>After:</p>
<p><code>_n_ _a_n_d_ _m_ _a_r_e_ _d_e_c_i_m_a_l_ _n_u_m_b_e_r_s_ _b_e_t_w_e_e_n_</code></p>
<p>&quot;As few as possible&quot; applied here means zero character replacements.          However match <b>does occur</b> between characters! To explain this behavior          I quote Bram himself:</p>
<p><cite>Matching zero characters is still a match. Thus it will replace          zero characters with a &quot;_&quot;. And then go on to the next position, where          it will match again. </cite></p>
<p><cite>It&#8217;s true that using &quot;\{-}&quot; is mostly useless. It works this way          to be consistent with &quot;*&quot;, which also matches zero characters. There are          more useless ones: &quot;x\{-1,}&quot; always matches one x. You could just use          &quot;x&quot;. More useful is something like &quot;x\{70}&quot;. The others are just consistent          behavior: &#8230;, &quot;x\{-3,}&quot;, &quot;x\{-2,}&quot;, &quot;x\{-1,}. </cite></p>
<p><cite>- Bram </cite></p>
<p>But what if we want to match only the second occurrence of quoted text?          Or we want to replace only a part of the quoted text keeping the rest          untouched? We will need <i>grouping</i> and <i>backreferences.</i> But          before let&#8217;s talk more about character ranges.</p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="ranges">4.4 Character ranges</a></h2>
<p>Typical character ranges:</p>
<p><code>[012345]</code> will match any of the numbers inside the brackets.          The same range can be written as <code>[0-5]</code>, where dash indicates          a range of characters in ASCII order. Likewise, we can define the range          for all lowercase letters: <code>[a-z]</code>, for all letters: <code>[a-zA-Z]</code>,          letters and digits: <code>[0-9a-zA-Z]</code> etc. Depending on your system          locale you can define range which will include characters like &agrave;,          &Ouml;, &szlig; and other non ASCII characters.</p>
<p>Note that the range represents just <i>one character</i> in the search          pattern, that is <code>[0123]</code> and <code>0123</code> are not the          same. Likewise the order (with a few exceptions) is not important: <code>[3210]</code>          and <code>[0123]</code> are the same character ranges, while <code>0123</code>          and <code>3210</code> are two different patterns. Watch what happens when          we apply</p>
<p><code>s:[65]:Dig:g</code></p>
<p>to the following text:</p>
<p>Before:</p>
<p><code>High <span class="match">65</span> to 70. Southeast wind around          10</code></p>
<p>After:</p>
<p><code>High <span class="replace">DigDig</span> to 70. Southeast wind          around 10</code></p>
<p>and now:</p>
<p><code>s:65:Dig:g</code></p>
<p>Before:</p>
<p><code>High <span class="match">65</span> to 70. Southeast wind around          10</code></p>
<p>After:</p>
<p><code>High <span class="replace">Dig</span> to 70. Southeast wind around          10</code></p>
<p>Sometimes it&#8217;s easier to define the characters you don&#8217;t want to match.          This is done by putting a negation sign <code>&quot;^&quot;</code> (caret)          as a first character of the range</p>
<p>/<code>[^A-Z]</code>/</p>
<p>- will match <i>any character</i> except capital letters. We can now          rewrite our pattern for quoted text using</p>
<p><code>/&quot;[^&quot;]\+&quot;</code>/</p>
<p>Note: inside the [ ] all metacharacters behave like ordinary characters.          If you want to include &quot;-&quot; (dash) in your range put it first</p>
<p><code>/[-0-9]/</code></p>
<p>- will match all digits <i>and </i> -. &quot;^&quot; will lose its special          meaning if it&#8217;s not the first character in the range.</p>
<p>Now, let&#8217;s have some real life example. Suppose you want to run a grammar          check on your file and find all places where new sentence does not start          with a capital letter. The pattern that will catch this:</p>
<p><code>\.\s\+[a-z] </code></p>
<p>- a period followed by one or more blanks and a lowercase word. We know          how to find an error, now let&#8217;s see how we can correct it. To do this          we need some ways to remember our matched pattern and recall it later.          That is exactly what <i>backreferences</i> are for.</p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="backreferences">4.5 Grouping and Backreferences</a></h2>
<p>You can group parts of the pattern expression enclosing them with &quot;<code>\(</code>&quot;          and &quot;<code>\)</code>&quot; and refer to them inside the replacement          pattern by their special number <code>\1, \2 ... \9</code>. Typical example          is swapping first two words of the line:</p>
<p>            <code>s:\(\w\+\)\(\s\+\)\(\w\+\):\3\2\1:</code></p>
<p>where <code>\1</code> holds the first word, <code>\2</code> &#8211; any number          of spaces or tabs in between and <code>\3</code> &#8211; the second word. How          to decide what number holds what pair of <code>\(\)</code> ? &#8211; count opening          &quot;<code>\(</code>&quot; from the left.</p>
<h2>Replacement Part of :substitute</h2>
<p>Replacement part of the S&amp;R has its own special characters which          we are going to use to fix grammar:</p>
<table cellspacing="3" class="vimdoc">
<tbody>
<tr>
<td width="43">
<div align="center"><b>#</b></div>
</td>
<td width="245">
<div align="center"><b>Meaning</b></div>
</td>
<td width="46">
<div align="center"><b>#</b></div>
</td>
<td width="225">
<div align="center"><b>Meaning</b></div>
</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>&amp;</b></div>
</td>
<td width="245">the whole matched pattern</td>
<td width="46">
<div align="center"><b>\L</b></div>
</td>
<td width="225">the following characters are made lowercase</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\0</b></div>
</td>
<td width="245">the whole matched pattern</td>
<td width="46">
<div align="center"><b>\U</b></div>
</td>
<td width="225">the following characters are made uppercase</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\1</b></div>
</td>
<td width="245">the matched pattern in the first pair of \(\)</td>
<td width="46">
<div align="center"><b>\E</b></div>
</td>
<td width="225">end of \U and \L</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\2</b></div>
</td>
<td width="245">the matched pattern in the second pair of \(\)</td>
<td width="46">
<div align="center"><b>\e</b></div>
</td>
<td width="225">end of \U and \L</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>&#8230;</b></div>
</td>
<td width="245">&#8230;</td>
<td width="46">
<div align="center"><b>\r</b></div>
</td>
<td width="225">split line in two at this point</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>\9</b></div>
</td>
<td width="245">the matched pattern in the ninth pair of \(\)</td>
<td width="43">
<div align="center"><b>\l </b></div>
</td>
<td width="245">next character made lowercase</td>
</tr>
<tr>
<td width="43">
<div align="center"><b>~</b></div>
</td>
<td width="245">the previous substitute string</td>
<td width="43">
<div align="center"><b>\u</b></div>
</td>
<td width="245">next character made uppercase</td>
</tr>
</tbody>
</table>
<p>Now the full S&amp;R to correct non-capital words at the beginning of          the sentences looks like</p>
<p><code>s:\([.!?]\)\s\+\([a-z]\):\1&nbsp;&nbsp;\u\2:g</code></p>
<p>We have corrected our grammar and as an extra job we replaced variable          number of spaces between punctuation and the first letter of the next          sentence with exactly two spaces.</p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="alternations">4.6 Alternations</a></h2>
<p>Using &quot;<code>\|</code>&quot; you can combine several expressions          into one which matches any of its components. The first one matched will          be used.</p>
<p><code>\(Date:\|Subject:\|From:\)\(\s.*\)</code></p>
<p>            will parse various mail headings and their contents into \1 and \2, respectively.        The thing to remember about VIM alternation that it is not <i>greedy. </i>        It won&#8217;t search for the longest possible match, it will use the first that        matched. That means that the order of the items in the alternation is important!</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<div class="tip">
<p><b>Tip 3:</b> Quick mapping to put \(\) in your pattern string</p>
<p><code>cmap ;\ \(\)&lt;Left&gt;&lt;Left&gt;</code></p>
</p></div>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="precedence">4.7 Regexp Operator Precedence</a></h2>
<p>As in arithmetic expressions, regular expressions are executed in a certain          order of precedence. Here the table of precedence, from highest to lowest:</p>
<table cellspacing="3" class="vimdoc">
<tbody>
<tr>
<td width="94">
<div align="center"><b>Precedence</b></div>
</td>
<td width="192">
<div align="center"><b>Regexp</b></div>
</td>
<td width="261">
<div align="center"><b>Description</b></div>
</td>
</tr>
<tr>
<td width="94">
<div align="center"><b>1</b></div>
</td>
<td width="192">
<div align="center"><b>\( \)</b></div>
</td>
<td width="261">
<div align="center">grouping</div>
</td>
</tr>
<tr>
<td width="94">
<div align="center"><b>2</b></div>
</td>
<td width="192">
<div align="center"><b>\=,\+,*,\{n} etc.</b></div>
</td>
<td width="261">
<div align="center">quantifiers</div>
</td>
</tr>
<tr>
<td width="94">
<div align="center"><b>3</b></div>
</td>
<td width="192">
<div align="center"><b>abc\t\.\w</b></div>
</td>
<td width="261">
<div align="center">sequence of characters/ metacharacters, not containing                quantifiers or grouping operators</div>
</td>
</tr>
<tr>
<td width="94">
<div align="center"><b>4</b></div>
</td>
<td width="192">
<div align="center"><b>\|</b></div>
</td>
<td width="261">
<div align="center">alternation</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan="3">
<h1><a name="global">V. Global Command</a></h1>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="global search">5.1 Global search and execution</a></h2>
<p>I want to introduce another quite useful and powerful Vim command which          we&#8217;re going to use later</p>
<table cellspacing="3" class="vimdoc">
<tbody>
<tr>
<td colspan="2"><b>:<i>range</i> g[lobal][!]/<i>pattern</i>/<i>cmd</i></b></td>
</tr>
<tr>
<td colspan="2">Execute the Ex command <b><i>cmd</i></b> (default &quot;<b>:p</b>&quot;)              on the lines within [<b><i>range</i></b>] where <b><i>pattern</i></b>              matches. If <b><i>pattern</i></b> is preceded with a <b>!</b> &#8211; only              where match <b>does not</b> occur.</td>
</tr>
</tbody>
</table>
<p>The global commands work by first scanning through the [<i>range</i>]          of of the lines and marking each line where a match occurs. In a second          scan the [<i>cmd</i>] is executed for each marked line with its line number          prepended. If a line is changed or deleted its mark disappears. The default          for the [<i>range</i>] is the whole file.</p>
<p>Note: Ex commands are all commands you are entering on the Vim command          line like <code>:s[ubstitute], :co[py] , :d[elete], :w[rite] </code>etc.          Non-Ex commands (normal mode commands) can be also executed via</p>
<p><code>:norm[al]<i>non-ex command</i></code></p>
<p>mechanism.</p>
<h2><a name="global examples">5.2 Examples</a></h2>
<p>Some examples of <code>:global</code> usage:</p>
<p><code>:g/^$/ d</code></p>
<p>- delete all empty lines in a file</p>
<p><code>:g/^$/,/./-j</code></p>
<p>- reduce multiple blank lines to a single blank</p>
<p><code>:10,20g/^/ mo 10</code></p>
<p>- reverse the order of the lines starting from the line 10 up to the          line 20.</p>
<p>Here is a modified example from <a href="http://www.networkcomputing.com/unixworld/tutorial/009/009.html">Walter          Zintz vi tutorial</a>:</p>
<p><code>:'a,'b g/^Error/ . w &gt;&gt; errors.txt</code></p>
<p>- in the text block marked by <code>'a</code> and <code>'b </code>find          all the lines starting with <span class="pattern">Error</span> and copy          (append) them to &quot;errors.txt&quot; file.<b> Note:</b> . (current          line address) in front of the <code>w</code> is very important, omitting          it will cause <code>:write</code> to write the whole file to &quot;errors.txt&quot;          for every <span class="pattern">Error</span> line found.</p>
<p>You can give multiple commands after <code>:global </code>using &quot;|&quot;          as a separator. If you want to use &quot;|&#8217; in an argument, precede it          with &quot;\&#8217;. Another example from Zintz tutorial:</p>
<p><code>:g/^Error:/ copy $ | s /Error/copy of the error/</code></p>
<p>- will copy all <span class="pattern">Error</span> line to the end of          the file and then make a substitution in the copied line. Without giving          the line address <code>:s</code> will operate on the current line, which          is the newly copied line.</p>
<p><code>:g/^Error:/ s /Error/copy of the error/ | copy $</code></p>
<p>- here the order is reversed: first modify the string then copy to the          end.</p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="3">
<h1><a name="examples">VI. Examples</a></h1>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="tips">6.1 Tips and Techniques</a></h2>
<p>A collection of some useful S&amp;R tips:</p>
<p>(1) sent by Antonio Colombo:</p>
<p><cite>&quot;a simple regexp I use quite often to clean up a text: it          drops the blanks at the end of the line:&quot;</cite></p>
<p><code> s:\s*$::</code></p>
<p><cite>or (to avoid acting on all lines): </cite></p>
<p><code>s:\s\+$::</code></p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="contents">6.2 Creating outline</a></h2>
<p>For this example you need to know a bit of HTML. We want to make a table          of contents out of <code>h1</code> and <code>h2</code> headings, which          I will call majors and minors. HTML heading <code>h1</code> is a text          enclosed by <code>&lt;h1&gt;</code> tags as in <code>&lt;h1&gt;Heading&lt;/h1&gt;</code>.</p>
<p>(1) First let&#8217;s make named anchors in all headings, i.e. put <code>&lt;h1&gt;&lt;a          name=&quot;anchor&quot;&gt;Heading&lt;/a&gt;&lt;/h1&gt;</code> around          all headings. The <code>&quot;anchor</code>&quot; is a unique identifier          of this particular place in HTML document. The following S&amp;R does          exactly this:</p>
<p><code> :s:\(&lt;h[12]&gt;\)\(.*\s\+\([-a-zA-Z]\+\)\)\s*\(&lt;/h[12]&gt;\):\1&lt;a          name=&quot;\3&quot;&gt;\2&lt;/a&gt;\4:</code></p>
<p><b>Explanation:</b> the first pair of <code>\(\)</code> saves the opening          tag (<code>h1</code> or <code>h2</code>) to the <code>\1</code>, the second          pair saves all heading text before the closing tag, the third pair saves          the last word in the heading which we will later use for &quot;anchor&quot;          and the last pair saves the closing tag. The replacement is quite obvious          &#8211; we just reconstruct a new &quot;named&quot; heading using <code>\1-\4</code>          and link tag <code>&lt;a&gt;.</code></p>
<p>(2) Now let&#8217;s copy all headings to one place:</p>
<p><code>:%g/&lt;h[12]&gt;/ t$</code></p>
<p>This command searches our file for the lines starting with <code>&lt;h1&gt;</code>          or <code>&lt;h2&gt;</code> and copies them to the end of the file. Now          we have a bunch of lines like:</p>
<p><code>&lt;h1&gt;&lt;a name=&quot;anchor1&quot;&gt;Heading1&gt;&lt;/a&gt;&lt;/h1&gt;<br />
            &lt;h2&gt;&lt;a name=&quot;anchor2&quot;&gt;Heading2&gt;&lt;/a&gt;&lt;/h2&gt;<br />
            &lt;h2&gt;&lt;a name=&quot;anchor3&quot;&gt;Heading3&gt;&lt;/a&gt;&lt;/h2&gt;<br />
            ..........................<br />
            &lt;h1&gt;&lt;a name=&quot;anchorN&quot;&gt;HeadingN&gt;&lt;/a&gt;&lt;/h1&gt;</code></p>
<p>First, we want to convert all <code>name=&quot;</code> to <code>href=&quot;#</code>          in order to link table entries to their respective places in the text:</p>
<p><code>s:name=&quot;:href=&quot;#:</code></p>
<p>Second, we want our <code>h1</code> entries look different from <code>h2</code>.          Let&#8217;s define CSS classes &quot;majorhead&quot; and &quot;minorhead&quot;          and do the following:</p>
<p><code>g/&lt;h1&gt;/ s:&lt;a:&amp; class=&quot;majorhead&quot;:<br />
            g/&lt;h2&gt;/ s:&lt;a:&amp; class=&quot;minorhead&quot;: </code></p>
<p>Now our entries look like:</p>
<p><code>&lt;h1&gt;&lt;a class=&quot;majorhead&quot; name=&quot;anchor1&quot;&gt;Heading1&gt;&lt;/a&gt;&lt;/h1&gt;<br />
            &lt;h2&gt;&lt;a class=&quot;minorhead&quot; name=&quot;anchor2&quot;&gt;Heading2&gt;&lt;/a&gt;&lt;/h2&gt;</code></p>
<p>We no longer need <code>h1</code> and <code>h2</code> tags:</p>
<p><code>s:&lt;h[21]&gt;::</code></p>
<p>and replace closing tags with breaklines <code>&lt;br&gt;</code></p>
<p><code>s:/h[21]:br:</code></p>
<p><code>&lt;a class=&quot;majorhead&quot; name=&quot;anchor1&quot;&gt;Heading1&gt;&lt;/a&gt;&lt;br&gt;<br />
            &lt;a class=&quot;minorhead&quot; name=&quot;anchor2&quot;&gt;Heading2&gt;&lt;/a&gt;&lt;br&gt;</code></p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<h2><a name="tables">6.3 Working with Tables</a></h2>
<p>Quite often you have to work with a text organized in tables/columns.          Consider, for example, the following text</p>
<table border="0" align="center" width="500">
<tbody>
<tr>
<td>
<div align="center">Asia</div>
</td>
<td>
<div align="center">America</div>
</td>
<td>
<div align="center">Africa</div>
</td>
<td>
<div align="center">Europe</div>
</td>
</tr>
<tr>
<td>
<div align="center">Africa</div>
</td>
<td>
<div align="center">Europe</div>
</td>
<td>
<div align="center">Europe</div>
</td>
<td>
<div align="center">Africa</div>
</td>
</tr>
<tr>
<td>
<div align="center">Europe</div>
</td>
<td>
<div align="center">Asia</div>
</td>
<td>
<div align="center">Europe</div>
</td>
<td>
<div align="center">Europe</div>
</td>
</tr>
</tbody>
</table>
<p>Suppose we want to change all &quot;Europe&quot; cells in the third column          to &quot;Asia&quot;:</p>
<p><code>:%s:\(\(\w\+\s\+\)\{2}\)Europe:\1Asia:</code></p>
<table border="0" align="center" width="500">
<tbody>
<tr>
<td>
<div align="center">Asia</div>
</td>
<td>
<div align="center">America</div>
</td>
<td>
<div align="center">Africa</div>
</td>
<td>
<div align="center">Europe</div>
</td>
</tr>
<tr>
<td>
<div align="center">Africa</div>
</td>
<td>
<div align="center">Europe</div>
</td>
<td>
<div align="center" class="replace">Asia</div>
</td>
<td>
<div align="center">Africa</div>
</td>
</tr>
<tr>
<td>
<div align="center">Europe</div>
</td>
<td>
<div align="center">Asia</div>
</td>
<td>
<div align="center" class="replace">Asia</div>
</td>
<td>
<div align="center">Europe</div>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>To swap the first and the last columns:</p>
<p><code>:%s:\(\w\+\)\(.*\s\+\)\(\w\+\)$:\3\2\1:</code></p>
<table border="0" align="center" width="500">
<tbody>
<tr>
<td class="replace">
<div align="center">Europe</div>
</td>
<td>
<div align="center">America</div>
</td>
<td>
<div align="center">Africa</div>
</td>
<td class="replace">
<div align="center">Asia</div>
</td>
</tr>
<tr>
<td class="replace">
<div align="center">Africa</div>
</td>
<td>
<div align="center">Europe</div>
</td>
<td>
<div align="center">Europe</div>
</td>
<td class="replace">
<div align="center">Africa</div>
</td>
</tr>
<tr>
<td class="replace">
<div align="center">Europe</div>
</td>
<td>
<div align="center">Asia</div>
</td>
<td>
<div align="center">Europe</div>
</td>
<td class="replace">
<div align="center">Europe</div>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>To be continued&#8230;</p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="3">
<h1><a name="compare">VII. Other Regexp Flavors</a></h1>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<p>Here I would like to compare Vim&#8217;s regexp implementation with others,          in particular, Perl&#8217;s. You can&#8217;t talk about regular expressions without          mentioning Perl.</p>
<p>(with a help from <a href="mailto:skirkendall@uswest.net">Steve Kirkendall</a>)          The main differences between Perl and Vim are:</p>
<ul>
<li>Perl doesn&#8217;t require backslashes before most of its operators. Personally,            I think it makes regexps more readable &#8211; the less backlashes are there            the better.</li>
<li>Perl allows you to convert any quantifier into a non-greedy version            by adding an extra ? after it. So *? is a non-greedy *.</li>
<li>Perl supports a lots of weird options that can be appended to the            regexp, or even embedded in it.</li>
<li>You can also embed variable names in a Perl regular expression. Perl            replaces the name with its value; this is called &quot;variable interpolation&quot;.</li>
</ul>
</td>
</tr>
<tr>
<td colspan="3">
<h1><a name="links">VIII. Links</a></h1>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<p>Read VIM documentation about pattern and searching. To get this type          &quot;:help pattern&quot; in VIM normal mode.</p>
<p>There are currently two books on the market that deal with VIM regular          expressions:</p>
<ul>
<li><b><a href="http://www.oreilly.com/catalog/vi6/">&quot;Learning the            vi Editor&quot;</a></b> by Linda Lamb and Arnold Robbins.</li>
<li><b>&quot;<a href="http://www.oualline.com/">vi Improved &#8211; VIM</a>&quot;</b> by Steve Oualline</li>
</ul>
<p>Definitive reference on regular expressions is Jeffrey Friedl&#8217;s <b><a href="http://www.oreilly.com/catalog/regex/chapter/ch04.html">&quot;Mastering          Regular Expressions&quot;</a></b> published by O&#8217;Reilly &amp; Associates,          but it mostly deals with Perl regular expressions. O&#8217;Reilly has one of          the book chapters available online.</p>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="297">
<div align="left"><a href="http://us.geocities.yahoo.com/gb/sign?member=volontir"><font face="Arial, Helvetica, sans-serif" size="-1"><b>Sign          Guestbook</b></font></a></div>
</td>
<td width="298">
<div align="right"><a href="http://us.geocities.yahoo.com/gb/view?member=volontir"><font size="-1"><b>View          Guestbook</b></font></a><b><font size="-1">&nbsp;</font></b></div>
</td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="597" colspan="2">
<hr noshade="noshade" />
            </td>
</tr>
<tr>
<td width="29">&nbsp;</td>
<td width="297">
<table cellspacing="0" cellpadding="1" border="0" bgcolor="#660066" width="1%">
<tbody>
<tr>
<td>
<table cellspacing="0" cellpadding="3" border="0" bgcolor="#eeeeee" width="1%">
<tbody>
<tr>
<td width="1%"><a href="http://us.geocities.yahoo.com/pstats/volontir"><img height="14" border="0" width="14" alt="See who's visiting this page." src="http://pic.geocities.com/us/i/geo/ao/pstat.gif" /></a></td>
<td nowrap="nowrap"><font face="arial" size="-2"><a href="http://us.geocities.yahoo.com/pstats/volontir">View                    Page Stats</a></font></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
<td width="298" class="footer">Copyright &copy; 2000-2001, <a href="mailto:volontir%20at%20yahoo%20dot%20com">Oleg  			 Raisky</a>. Last update: Sun 27 2002</td>
</tr>
</tbody>
</table>
<p><!-- text below generated by server. PLEASE REMOVE --><br />
<script src="http://us.i1.yimg.com/us.yimg.com/i/mc/mc.js" language="JavaScript" type="text/javascript"></script><br />
<script src="http://us.geocities.com/js_source/geov2.js" language="JavaScript" type="text/javascript"></script><br />
<script language="javascript" type="text/javascript">geovisit();</script><br />
<img border="0" src="http://visit.geocities.com/visit.gif?&amp;r=http%3A//www.geocities.com/volontir/%3F200915&amp;b=Netscape%205.0%20%28Windows%3B%20es-ES%29&amp;s=1024x768&amp;o=Win32&amp;c=16&amp;j=true&amp;v=1.2" alt="" /> <noscript>&lt;img src=&quot;http://visit.geocities.com/visit.gif?1012147342&quot; border=0 width=1 height=1&gt;</noscript> <img height="1" width="1" alt="1" src="http://geo.yahoo.com/serv?s=76001067&amp;t=1012147342" /> <!-- text below generated by server. PLEASE REMOVE --><br />
<script src="http://us.i1.yimg.com/us.yimg.com/i/mc/mc.js" language="JavaScript" type="text/javascript"></script><br />
<script src="http://us.js2.yimg.com/us.js.yimg.com/lib/smb/js/hosting/cp/js_source/geov2_001.js" language="JavaScript" type="text/javascript"></script><br />
<script language="javascript" type="text/javascript">geovisit();</script><br />
<noscript>&lt;img src=&quot;http://visit.geocities.yahoo.com/visit.gif?us1253033119&quot; alt=&quot;setstats&quot; border=&quot;0&quot; width=&quot;1&quot; height=&quot;1&quot;&gt;</noscript> <img height="1" width="1" alt="1" src="http://geo.yahoo.com/serv?s=76001067&amp;t=1253033119&amp;f=us-w6" /></p>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2009/09/expresiones-regulares-para-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parseo en Bash (Linux Shell Scripting)</title>
		<link>http://smultron.es/2009/09/parseo-en-bash-linux-shell-scripting/</link>
		<comments>http://smultron.es/2009/09/parseo-en-bash-linux-shell-scripting/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 21:22:46 +0000</pubDate>
		<dc:creator>NEO</dc:creator>
				<category><![CDATA[copy&page]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://smultron.es/?p=4465</guid>
		<description><![CDATA[&#160;Ultimamente, he estado programando en shell scripting, obteniendo y guardando muchos datos tales como Nombres de las m&#225;quinas que est&#225;n en mi red. O automatizando la identificaci&#243;n de dominios caidos. No es dificil Obtener estos datos, sino tratarlos para que aporten algo de informaci&#243;n facilmente. Para ello hasta ahora me val&#237;a de los comandos de [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;Ultimamente, he estado programando en shell scripting, obteniendo y guardando muchos datos tales como Nombres de las m&aacute;quinas que est&aacute;n en mi red. O automatizando la identificaci&oacute;n de dominios caidos.</p>
<p>No es dificil Obtener estos datos, sino tratarlos para que aporten algo de informaci&oacute;n facilmente. Para ello hasta ahora me val&iacute;a de los comandos de vi (editor de textos de linux).</p>
<p>PERO!, el Frotar se va a acabar, porque he encontrado este comando que nos facilitar&aacute; la vida para Parsear archivos:</p>
<p>SED</p>
<p>Copy&amp;Page:&nbsp;<a href="http://www.grymoire.com/Unix/Sed.html">http://www.grymoire.com/Unix/Sed.html</a></p>
<p><span id="more-4465"></span><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; "></p>
<h1>Sed &#8211; An Introduction and Tutorial</h1>
<h2>Bruce Barnett</h2>
<p>
Last update: Wed Jul 15 EDT 2009&nbsp;<br />
Thanks to Keelan Evans, Fredrik Nilsson, and Kurt McKee for spotting some typos.&nbsp;<br />
Thanks to Wim Stolker and Jose&#8217; Sebrosa as well.&nbsp;<br />
Thanks to Olivier Mengue.&nbsp;<br />
Thanks to Andrew M. Goth.&nbsp;<br />
Thanks to David P. Brown.&nbsp;<br />
Thanks to Axel Schulze for some corrections&nbsp;<br />
Thanks to Martin Jan for the corrections in sed format (grin)&nbsp;<br />
A big thanks for Fazl Rahman for spotting dozens of errors.&nbsp;</p>
<h2>Table of Contents</h2>
<ul>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-0" name="toc-uh-0">The Awful Truth about sed</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-1" name="toc-uh-1">The essential command: s for substitution</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-2" name="toc-uh-2">The slash as a delimiter</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-3" name="toc-uh-3">Using &amp; as the matched string</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-4" name="toc-uh-4">Using \1 to keep part of the pattern</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-5" name="toc-uh-5">Substitute Flags</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-6" name="toc-uh-6">/g &#8211; Global replacement</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-7" name="toc-uh-7">Is sed recursive?</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-8" name="toc-uh-8">/1, /2, etc. Specifying which occurrence</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-9" name="toc-uh-9">/p &#8211; print</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-10" name="toc-uh-10">Write to a file with /w filename</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-11" name="toc-uh-11">Combining substitution flags</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-12" name="toc-uh-12">Arguments and invocation of sed</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-13" name="toc-uh-13">Multiple commands with -e command</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-14" name="toc-uh-14">Filenames on the command line</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-15" name="toc-uh-15">sed -n: no printing</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-16" name="toc-uh-16">sed -f scriptname</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-17" name="toc-uh-17">sed in shell script</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-18" name="toc-uh-18">Quoting multiple sed lines in the C shell</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-19" name="toc-uh-19">Quoting multiple sed lines in the Bourne shell</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-20" name="toc-uh-20">A sed interpreter script</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-21" name="toc-uh-21">Sed Comments</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-22" name="toc-uh-22">Passing arguments into a sed script</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-23" name="toc-uh-23">Using sed in a shell here-is document</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-24" name="toc-uh-24">Multiple commands and order of execution</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-25" name="toc-uh-25">Addresses and Ranges of Text</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-26" name="toc-uh-26">Restricting to a line number</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-27" name="toc-uh-27">Patterns</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-28" name="toc-uh-28">Ranges by line number</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-29" name="toc-uh-29">Ranges by patterns</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-30" name="toc-uh-30">Delete with d</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-31" name="toc-uh-31">Printing with p</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-32" name="toc-uh-32">Reversing the restriction with !</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-33" name="toc-uh-33">Relationships between d, p, and !</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-34" name="toc-uh-34">The q or quit command</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-35" name="toc-uh-35">Grouping with { and }</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-36" name="toc-uh-36">Writing a file with the &#8216;w&#8217; command</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-37" name="toc-uh-37">Reading in a file with the &#8216;r&#8217; command</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-38" name="toc-uh-38">SunOS and the # Comment Command</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-39" name="toc-uh-39">Adding, Changing, Inserting new lines</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-40" name="toc-uh-40">Append a line with &#8216;a&#8217;</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-41" name="toc-uh-41">Insert a line with &#8216;i&#8217;</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-42" name="toc-uh-42">Change a line with &#8216;c&#8217;</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-43" name="toc-uh-43">Leading tabs and spaces in a sed script</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-44" name="toc-uh-44">Adding more than one line</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-45" name="toc-uh-45">Adding lines and the pattern space</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-46" name="toc-uh-46">Address ranges and the above commands</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-47" name="toc-uh-47">Multi-Line Patterns</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-48" name="toc-uh-48">Print line number with =</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-49" name="toc-uh-49">Transform with y</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-50" name="toc-uh-50">Displaying control characters with a l</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-51" name="toc-uh-51">Working with Multiple Lines</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-nl" name="toc-uh-nl">Using newlines in sed scripts</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-52" name="toc-uh-52">The Hold Buffer</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-53" name="toc-uh-53">Exchange with x</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-54" name="toc-uh-54">Example of Context Grep</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-55" name="toc-uh-55">Hold with h or H</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-56" name="toc-uh-56">Keeping more than one line in the hold buffer</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-57" name="toc-uh-57">Get with g or G</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-58" name="toc-uh-58">Flow Control</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-59" name="toc-uh-59">Testing with t</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-60" name="toc-uh-60">An alternate way of adding comments</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-61" name="toc-uh-61">The poorly undocumented ;</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-62" name="toc-uh-62">Passing regular expressions as arguments</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-63" name="toc-uh-63">Command Summary</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-64" name="toc-uh-64">In Conclusion</a></li>
<li><a href="http://www.grymoire.com/Unix/Sed.html#uh-65" name="toc-uh-65">More References</a></li>
</ul>
<p>Copyright 2001,2005,2007 Bruce Barnett and General Electric Company</p>
<p>All rights reserved</p>
<p>You are allowed to print copies of this tutorial for your personal use, and link to this page, but you are not allowed to make electronic copies, or redistribute this tutorial in any form without permission.</p>
<p>&nbsp;</p>
<h1>Introduction to Sed</h1>
<p>How to use sed, a special editor for modifying files automatically. If you want to write a program to make changes in a file, sed is the tool to use.</p>
<p>There are a few programs that are the real workhorse in the Unix toolbox. These programs are simple to use for simple applications, yet have a rich set of commands for performing complex actions. Don&#8217;t let the complex potential of a program keep you from making use of the simpler aspects. This chapter, like all of the rest, start with the simple concepts and introduces the advanced topics later on.&nbsp;<br />
A note on comments. When I first wrote this, most versions of sed did not allow you to place comments inside the script. Lines starting with the &#8216;#&#8217; characters are comments. Newer versions of sed may support comments at the end of the line as well.</p>
<p>&nbsp;</p>
<h1><a name="uh-0" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-0">The Awful Truth about sed</a></h1>
<p><i>Sed</i>&nbsp;is the ultimate&nbsp;<b>s</b>tream&nbsp;<b>ed</b>itor. If that sounds strange, picture a stream flowing through a pipe. Okay, you can&#8217;t see a stream if it&#8217;s inside a pipe. That&#8217;s what I get for attempting a flowing analogy. You want literature, read James Joyce.</p>
<p>Anyhow,&nbsp;<i>sed</i>&nbsp;is a marvelous utility. Unfortunately, most people never learn its real power. The language is very simple, but the documentation is terrible. The Solaris on-line manual pages for&nbsp;<i>sed</i>&nbsp;are five pages long, and two of those pages describe the 34 different errors you can get. A program that spends as much space documenting the errors than it does documenting the language has a serious learning curve.</p>
<p><b>Do not fret!</b>&nbsp;It is not your fault you don&#8217;t understand&nbsp;<i>sed</i>. I will cover&nbsp;<i>sed</i>&nbsp;completely. But I will describe the features in the order that I learned them. I didn&#8217;t learn everything at once. You don&#8217;t need to either.</p>
<p>&nbsp;</p>
<h1><a name="uh-1" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-1">The essential command: s for substitution</a></h1>
<p><i>Sed</i>&nbsp;has several commands, but most people only learn the substitute command:&nbsp;<i>s</i>. The substitute command changes all occurrences of the regular expression into a new value. A simple example is changing &quot;day&quot; in the &quot;old&quot; file to &quot;night&quot; in the &quot;new&quot; file:</p>
<dl>
<dd>sed s/day/night/ &lt;old &gt;new
</dd>
</dl>
<p>Or another way (for Unix beginners),</p>
<dl>
<dd>sed s/day/night/ old &gt;new
</dd>
</dl>
<p>and for those who want to test this:</p>
<dl>
<dd>echo day | sed s/day/night/&nbsp;
</dd>
</dl>
<p>This will output &quot;night&quot;.</p>
<p>I didn&#8217;t put quotes around the argument because this example didn&#8217;t need them. If you read my earlier tutorial, you would understand why it doesn&#8217;t need quotes. However, I recommend you do use quotes. If you have meta-characters in the command, quotes are necessary. And if you aren&#8217;t sure, it&#8217;s a good habit, and I will henceforth quote future examples to emphasize the &quot;best practice.&quot; Using the strong (single quote) character, that would be:</p>
<dl>
<dd>sed &#8216;s/day/night/&#8217; &lt;old &gt;new
</dd>
</dl>
<p>I must emphasize the the sed editor changes exactly what you tell it to. So if you executed</p>
<dl>
<dd>echo Sunday | sed &#8216;s/day/night/&#8217; &lt;old &gt;new
</dd>
</dl>
<p>This would output the word &quot;Sunnight&quot; bacause sed found the string &quot;day&quot; in the input.</p>
<p>There are four parts to this substitute command:</p>
<pre>
s	  Substitute command
/../../	  Delimiter
day	  Regular Expression Pattern Search Pattern
night	  Replacement string
</pre>
<p>The search pattern is on the left hand side and the replacement string is on the right hand side.</p>
<p>We&#8217;ve covered&nbsp;<a href="http://www.grymoire.com/Unix/Quote.html">quoting</a>&nbsp;and&nbsp;<a href="http://www.grymoire.com/Unix/Regular.html">regular expressions.</a>. That&#8217;s 90% of the effort needed to learn the substitute command. To put it another way, you already know how to handle 90% of the most frequent uses of<i>sed.</i>&nbsp;There are a &#8230; few fine points that an future sed expert should know about. (You just finished section 1. There&#8217;s only 63 more sections to cover. :-) Oh. And you may want to bookmark this page, &#8230;. just in case you don&#8217;t finish.</p>
<p>&nbsp;</p>
<h1><a name="uh-2" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-2">The slash as a delimiter</a></h1>
<p>The character after the&nbsp;<i>s</i>&nbsp;is the delimiter. It is conventionally a slash, because this is what&nbsp;<i>ed</i>,&nbsp;<i>more</i>, and&nbsp;<i>vi</i>&nbsp;use. It can be anything you want, however. If you want to change a pathname that contains a slash &#8211; say /usr/local/bin to /common/bin &#8211; you could use the backslash to quote the slash:</p>
<dl>
<dd>sed &#8216;s/\/usr\/local\/bin/\/common\/bin/&#8217; &lt;old &gt;new
</dd>
</dl>
<p>Gulp. Some call this a &#8216;Picket Fence&#8217; and it&#8217;s ugly. It is easier to read if you use an underline instead of a slash as a delimiter:</p>
<dl>
<dd>sed &#8216;s_/usr/local/bin_/common/bin_&#8217; &lt;old &gt;new
</dd>
</dl>
<p>Some people use colons:</p>
<dl>
<dd>sed &#8216;s:/usr/local/bin:/common/bin:&#8217; &lt;old &gt;new
</dd>
</dl>
<p>Others use the &quot;|&quot; character.</p>
<dl>
<dd>sed &#8216;s|/usr/local/bin|/common/bin|&#8217; &lt;old &gt;new
</dd>
</dl>
<p>Pick one you like. As long as it&#8217;s not in the string you are looking for, anything goes. And remember that you need three delimiters. If you get a &quot;Unterminated `s&#8217; command&quot; it&#8217;s because you are missing one of them.</p>
<p>&nbsp;</p>
<h1><a name="uh-3" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-3">Using &amp; as the matched string</a></h1>
<p>Sometimes you want to search for a pattern and add some characters, like parenthesis, around or near the pattern you found. It is easy to do this if you are looking for a particular string:</p>
<dl>
<dd>sed &#8216;s/abc/(abc)/&#8217; &lt;old &gt;new
</dd>
</dl>
<p>This won&#8217;t work if you don&#8217;t know exactly what you will find. How can you put the string you found in the replacement string if you don&#8217;t know what it is?</p>
<p>The solution requires the special character &quot;&amp;.&quot; It corresponds to the pattern found.</p>
<dl>
<dd>sed &#8216;s/[a-z]*/(&amp;)/&#8217; &lt;old &gt;new
</dd>
</dl>
<p>You can have any number of &quot;&amp;&quot; in the replacement string. You could also double a pattern, e.g. the first number of a line:</p>
<dl>
<dd>%&nbsp;<b>echo &quot;123 abc&quot; | sed &#8216;s/[0-9]*/&amp; &amp;/&#8217;</b><br />
123 123 abc
</dd>
</dl>
<p>Let me slightly amend this example. Sed will match the first string, and make it as greedy as possible. The first match for &#8216;[0-9]*&#8217; is the first character on the line, as this matches zero of more numbers. So if the input was &quot;abc 123&quot; the output would be unchanged (well, except for a space before the letters). A better way to duplicate the number is to make sure it matches a number:</p>
<dl>
<dd>%&nbsp;<b>echo &quot;123 abc&quot; | sed &#8216;s/[0-9][0-9]*/&amp; &amp;/&#8217;</b><br />
123 123 abc
</dd>
</dl>
<p>The string &quot;abc&quot; is unchanged, because it was not matched by the regular expression. If you wanted to eliminate &quot;abc&quot; from the output, you must expand the the regular expression to match the rest of the line and explicitly exclude part of the expression using &quot;(&quot;, &quot;)&quot; and &quot;\1&quot;, which is the next topic.</p>
<p>&nbsp;</p>
<h1><a name="uh-4" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-4">Using \1 to keep part of the pattern</a></h1>
<p>I have already described the use of &quot;(&quot; &quot;)&quot; and &quot;1&quot; in my tutorial on&nbsp;<a href="http://www.grymoire.com/Unix/Regular.html">regular expressions.</a>&nbsp;To review, the escaped parentheses (that is, parentheses with backslashes before them) remember portions of the regular expression. You can use this to exclude part of the regular expression. The &quot;\1&quot; is the first remembered pattern, and the &quot;\2&quot; is the second remembered pattern. Sed has up to nine remembered patterns.</p>
<p>If you wanted to keep the first word of a line, and delete the rest of the line, mark the important part with the parenthesis:</p>
<dl>
<dd>sed &#8216;s/\([a-z]*\).*/\1/&#8217;
</dd>
</dl>
<p>I should elaborate on this. Regular exprssions are greedy, and try to match as much as possible. &quot;[a-z]*&quot; matches zero or more lower case letters, and tries to be as big as possible. The &quot;.*&quot; matches zero or more characters after the first match. Since the first one grabs all of the lower case letters, the second matches anything else. Therefore if you type</p>
<dl>
<dd>echo abcd123 | sed &#8216;s/\([a-z]*\).*/\1/&#8217;
</dd>
</dl>
<p>This will output &quot;abcd&quot; and delete the numbers.</p>
<p>If you want to switch two words around, you can remember two patterns and change the order around:</p>
<dl>
<dd>sed &#8216;s/\([a-z]*\) \([a-z]*\)/\2 \1/&#8217;
</dd>
</dl>
<p>Note the space between the two remembered patterns. This is used to make sure two words are found.</p>
<p>The &quot;\1&quot; doesn&#8217;t have to be in the replacement string (in the right hand side). It can be in the pattern you are searching for (in the left hand side). If you want to eliminate duplicated words, you can try:</p>
<dl>
<dd>sed &#8216;s/\([a-z]*\) \1/\1/&#8217;
</dd>
</dl>
<p>You can have up to nine values: &quot;\1&quot; thru &quot;\9.&quot;</p>
<p>&nbsp;</p>
<h1><a name="uh-5" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-5">Substitute Flags</a></h1>
<p>You can add additional flags after the last delimiter. These flags can specify what happens when there is more than one occurrence of a pattern on a single line, and what to do if a substitution is found. Let me describe them.</p>
<p>&nbsp;</p>
<h1><a name="uh-6" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-6">/g &#8211; Global replacement</a></h1>
<p>Most Unix utilties work on files, reading a line at a time.&nbsp;<i>Sed</i>, by default, is the same way. If you tell it to change a word, it will only change the first occurrence of the word on a line. You may want to make the change on every word on the line instead of the first. For an example, let&#8217;s place parentheses around words on a line. Instead of using a pattern like &quot;[A-Za-z]*&quot; which won&#8217;t match words like &quot;won&#8217;t,&quot; we will use a pattern, &quot;[^ ]*,&quot; that matches everything except a space. Well, this will also match anything because &quot;*&quot; means&nbsp;<b>zero or more</b>. The current version of&nbsp;<i>sed</i>&nbsp;can get unhappy with patterns like this, and generate errors like &quot;Output line too long&quot; or even run forever. I consider this a bug, and have reported this to Sun. As a work-around, you must avoid matching the null string when using the &quot;g&quot; flag to&nbsp;<i>sed</i>. A work-around example is: &quot;[^ ][^ ]*.&quot; The following will put parenthesis around the first word:</p>
<dl>
<dd>sed &#8216;s/[^ ]*/(&amp;)/&#8217; &lt;old &gt;new
</dd>
</dl>
<p>If you want it to make changes for every word, add a &quot;g&quot; after the last delimiter and use the work-around:</p>
<dl>
<dd>sed &#8216;s/[^ ][^ ]*/(&amp;)/g&#8217; &lt;old &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-7" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-7">Is sed recursive?</a></h1>
<p><i>Sed</i>&nbsp;only operates on patterns found in the in-coming data. That is, the input line is read, and when a pattern is matched, the modified output is generated, and the&nbsp;<b>rest</b>&nbsp;of the input line is scanned. The &quot;s&quot; command will not scan the newly created output. That is, you don&#8217;t have to worry about expressions like:</p>
<dl>
<dd>sed &#8216;s/loop/loop the loop/g&#8217; &lt;old &gt;new
</dd>
</dl>
<p>This will not cause an infinite loop. If a second &quot;s&quot; command is executed, it could modify the results of a previous command. I will show you how to execute multiple commands later.</p>
<p>&nbsp;</p>
<h1><a name="uh-8" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-8">/1, /2, etc. Specifying which occurrence</a></h1>
<p>With no flags, the first pattern is changed. With the &quot;g&quot; option, all patterns are changed. If you want to modify a particular pattern that is not the first one on the line, you could use &quot;\(&quot; and &quot;\)&quot; to mark each pattern, and use &quot;\1&quot; to put the first pattern back unchanged. This next example keeps the first word on the line but deletes the second:</p>
<dl>
<dd>sed &#8216;s/\([a-zA-Z]*\) \([a-zA-Z]*\) /\1 /&#8217; &lt;old &gt;new
</dd>
</dl>
<p>Yuck. There is an easier way to do this. You can add a number after the substitution command to indicate you only want to match that particular pattern. Example:</p>
<dl>
<dd>sed &#8216;s/[a-zA-Z]* //2&#8242; &lt;old &gt;new
</dd>
</dl>
<p>You can combine a number with the g (global) flag. For instance, if you want to leave the first world alone alone, but change the second, third, etc. to DELETED, use /2g:</p>
<dl>
<dd>sed &#8216;s/[a-zA-Z]* /DELETED /2g&#8217; &lt;old &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<p>Don&#8217;t get /2 and \2 confused. The /2 is used at the end. \2 is used in inside the replacement field.</p>
<p>Note the space after the &quot;*&quot; character. Without the space,&nbsp;<i>sed</i>&nbsp;will run a long, long time. (Note: this bug is probably fixed by now.) This is because the number flag and the &quot;g&quot; flag have the same bug. You should also be able to use the pattern</p>
<dl>
<dd>sed &#8216;s/[^ ]*//2&#8242; &lt;old &gt;new
</dd>
</dl>
<p>but this also eats CPU. If this works on your computer, and it does on some Unix systems, you could remove the encrypted password from the password file:</p>
<dl>
<dd>sed &#8216;s/[^:]*//2&#8242; &lt;/etc/passwd &gt;/etc/password.new
</dd>
</dl>
<p>But this didn&#8217;t work for me the time I wrote thise. Using &quot;[^:][^:]*&quot; as a work-around doesn&#8217;t help because it won&#8217;t match an non-existent password, and instead delete the third field, which is the user ID! Instead you have to use the ugly parenthesis:</p>
<dl>
<dd>sed &#8216;s/^\([^:]*\):[^:]:/\1::/&#8217; &lt;/etc/passwd &gt;/etc/password.new
</dd>
</dl>
<p>You could also add a character to the first pattern so that it no longer matches the null pattern:</p>
<dl>
<dd>sed &#8216;s/[^:]*:/:/2&#8242; &lt;/etc/passwd &gt;/etc/password.new
</dd>
</dl>
<p>&nbsp;</p>
<p>The number flag is not restricted to a single digit. It can be any number from 1 to 512. If you wanted to add a colon after the 80th character in each line, you could type:</p>
<dl>
<dd>sed &#8216;s/./&amp;:/80&#8242; &lt;file &gt;new
</dd>
</dl>
<p>You can also do it the hard way by using 80 dots:</p>
<dl>
<dd>sed &#8216;s/^&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;../&amp;:/&#8217; &lt;file &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-9" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-9">/p &#8211; print</a></h1>
<p>By default,&nbsp;<i>sed</i>&nbsp;prints every line. If it makes a substitution, the new text is printed instead of the old one. If you use an optional argument to sed, &quot;sed -n,&quot; it will not, by default, print any new lines. I&#8217;ll cover this and other options later. When the &quot;-n&quot; option is used, the &quot;p&quot; flag will cause the modified line to be printed. Here is one way to duplicate the function of&nbsp;<i>grep</i>&nbsp;with&nbsp;<i>sed</i>:</p>
<dl>
<dd>sed -n &#8216;s/pattern/&amp;/p&#8217; &lt;file
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-10" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-10">Write to a file with /w filename</a></h1>
<p>There is one more flag that can follow the third delimiter. With it, you can specify a file that will receive the modified data. An example is the following, which will write all lines that start with an even number to the file&nbsp;<i>even</i>:</p>
<dl>
<dd>sed -n &#8216;s/^[0-9]*[02468] /&amp;/w even&#8217; &lt;file&nbsp;
</dd>
</dl>
<p>In this example, the output file isn&#8217;t needed, as the input was not modified. You must have exactly one space between the&nbsp;<i>w</i>&nbsp;and the filename. You can also have ten files open with one instance of&nbsp;<i>sed</i>. This allows you to split up a stream of data into separate files. Using the previous example combined with multiple substitution commands described later, you could split a file into ten pieces depending on the last digit of the first number. You could also use this method to log error or debugging information to a special file.</p>
<p>&nbsp;</p>
<h1><a name="uh-11" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-11">Combining substitution flags</a></h1>
<p>You can combine flags when it makes sense. Also &quot;w&quot; has to be the last flag. For example the following command works:</p>
<dl>
<dd>sed -n &#8216;s/a/A/2pw /tmp/file&#8217; &lt;old &gt;new
</dd>
</dl>
<p>Next I will discuss the options to&nbsp;<i>sed</i>, and different ways to invoke&nbsp;<i>sed</i>.</p>
<p>&nbsp;</p>
<h1><a name="uh-12" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-12">Arguments and invocation of sed</a></h1>
<p>previously, I have only used one substitute command. If you need to make two changes, and you didn&#8217;t want to read the manual, you could pipe together multiple&nbsp;<i>sed</i>&nbsp;commands:</p>
<dl>
<dd>sed &#8216;s/BEGIN/begin/&#8217; &lt;old | sed &#8216;s/END/end/&#8217; &gt;new
</dd>
</dl>
<p>This used two processes instead of one. A&nbsp;<i>sed</i>&nbsp;guru never uses two processes when one can do.</p>
<p>&nbsp;</p>
<h1><a name="uh-13" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-13">Multiple commands with -e command</a></h1>
<p>One method of combining multiple commands is to use a&nbsp;<i>-e</i>&nbsp;before each command:</p>
<dl>
<dd>sed -e &#8216;s/a/A/&#8217; -e &#8216;s/b/B/&#8217; &lt;old &gt;new
</dd>
</dl>
<p>A &quot;-e&quot; isn&#8217;t needed in the earlier examples because&nbsp;<i>sed</i>&nbsp;knows that there must always be one command. If you give&nbsp;<i>sed</i>&nbsp;one argument, it must be a command, and&nbsp;<i>sed</i>&nbsp;will edit the data read from standard input.</p>
<p>Also see&nbsp;<a href="http://www.grymoire.com/Unix/Sed.html#uh-19">Quoting multiple sed lines in the Bourne shell</a></p>
<p>&nbsp;</p>
<h1><a name="uh-14" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-14">Filenames on the command line</a></h1>
<p>You can specify files on the command line if you wish. If there is more than one argument to&nbsp;<i>sed</i>&nbsp;that does not start with an option, it must be a filename. This next example will count the number of lines in three files that don&#8217;t begin with a &quot;#:&quot;</p>
<dl>
<dd>sed &#8216;s/^#.*//&#8217; f1 f2 f3 | grep -v &#8216;^$&#8217; | wc -l
</dd>
</dl>
<p>The&nbsp;<i>sed</i>&nbsp;substitute command changes every line that starts with a &quot;#&quot; into a blank line.&nbsp;<i>Grep</i>&nbsp;was used to filter out empty lines.&nbsp;<i>Wc</i>&nbsp;counts the number of lines left.&nbsp;<i>Sed</i>&nbsp;has more commands that make&nbsp;<i>grep</i>unnecessary. But I will cover that later.</p>
<p>Of course you could write the last example using the &quot;-e&quot; option:</p>
<dl>
<dd>sed -e &#8216;s/^#.*//&#8217; f1 f2 f3 | grep -v &#8216;^$&#8217; | wc -l
</dd>
</dl>
<p>There are two other options to&nbsp;<i>sed.</i></p>
<p>&nbsp;</p>
<h1><a name="uh-15" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-15">sed -n: no printing</a></h1>
<p>The &quot;-n&quot; option will not print anything unless an explicit request to print is found. I mentioned the &quot;/p&quot; flag to the substitute command as one way to turn printing back on. Let me clarify this. The command</p>
<dl>
<dd>sed &#8216;s/PATTERN/&amp;/p&#8217; file
</dd>
</dl>
<p>acts like the&nbsp;<i>cat</i>&nbsp;program if PATTERN is not in the file: e.g. nothing is changed. If PATTERN is in the file, then each line that has this is printed twice. Add the &quot;-n&quot; option and the example acts like grep:</p>
<dl>
<dd>sed -n &#8216;s/PATTERN/&amp;/p&#8217; file
</dd>
</dl>
<p>Nothing is printed, except those lines with PATTERN included.</p>
<p>&nbsp;</p>
<h1><a name="uh-16" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-16">sed -f scriptname</a></h1>
<p>If you have a large number of&nbsp;<i>sed</i>&nbsp;commands, you can put them into a file and use</p>
<dl>
<dd>sed -f sedscript &lt;old &gt;new
</dd>
</dl>
<p>where&nbsp;<i>sedscript</i>&nbsp;could look like this:</p>
<dl>
<dd># sed comment &#8211; This script changes lower case vowels to upper case<br />
s/a/A/g<br />
s/e/E/g<br />
s/i/I/g<br />
s/o/O/g<br />
s/u/U/g
</dd>
</dl>
<p>When there are several commands in one file, each command must be on a separate line.</p>
<p>Also see&nbsp;<a href="http://www.grymoire.com/Unix/Sed.html#uh-20">here</a></p>
<p>&nbsp;</p>
<h1><a name="uh-17" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-17">sed in shell script</a></h1>
<p>If you have many commands and they won&#8217;t fit neatly on one line, you can break up the line using a backslash:</p>
<dl>
<dd>sed -e &#8216;s/a/A/g&#8217; \<br />
-e &#8216;s/e/E/g&#8217; \<br />
-e &#8216;s/i/I/g&#8217; \<br />
-e &#8216;s/o/O/g&#8217; \<br />
-e &#8216;s/u/U/g&#8217; &lt;old &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-18" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-18">Quoting multiple sed lines in the C shell</a></h1>
<p>You can have a large, multi-line&nbsp;<i>sed</i>&nbsp;script in the C shell, but you must tell the C shell that the quote is continued across several lines. This is done by placing a backslash at the end of each line:</p>
<dl>
<dd>#!/bin/csh -f<br />
sed &#8216;s/a/A/g \<br />
s/e/E/g \<br />
s/i/I/g \<br />
s/o/O/g \<br />
s/u/U/g&#8217; &lt;old &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-19" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-19">Quoting multiple sed lines in the Bourne shell</a></h1>
<p>The Bourne shell makes this easier as a quote can cover several lines:</p>
<dl>
<dd>#!/bin/sh<br />
sed &#8216;<br />
s/a/A/g&nbsp;<br />
s/e/E/g&nbsp;<br />
s/i/I/g&nbsp;<br />
s/o/O/g&nbsp;<br />
s/u/U/g&#8217; &lt;old &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-20" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-20">A sed interpreter script</a></h1>
<p>Another way of executing&nbsp;<i>sed</i>&nbsp;is to use an interpreter script. Create a file that contains:&nbsp;</p>
<p>#!/bin/sed -f<br />
s/a/A/g<br />
s/e/E/g<br />
s/i/I/g<br />
s/o/O/g<br />
s/u/U/g</p>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/CapVowel.sed">CapVowel.sed</a><br />
If this script was stored in a file with the name &quot;CapVowel&quot; and was executable, you could use it with the simple command:</p>
<dl>
<dd>CapVowel &lt;old &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-21" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-21">Comments</a></h1>
<p><i>Sed</i>&nbsp;comments are lines where the first non-white character is a &quot;#.&quot; On many systems,&nbsp;<i>sed</i>&nbsp;can have only one comment, and it must be the first line of the script. On the Sun (1988 when I wrote this), you can have several comment lines anywhere in the script. Modern versions of Sed support this. If the first line contains exactly &quot;#n&quot; then this does the same thing as the &quot;-n&quot; option: turning off printing by default. This could not done with a&nbsp;<i>sed</i>&nbsp;interpreter script, because the first line must start with &quot;#!/bin/sed -f&quot; as I think &quot;#!/bin/sed -nf&quot; generated an error. It works as I write this update in 2008. Note that &quot;#!/bin/sed -fn&quot; does not work because sed thinks the filename of the script is &quot;n&quot;.</p>
<p>&nbsp;</p>
<h1><a name="uh-22" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-22">Passing arguments into a sed script</a></h1>
<p>Passing a word into a shell script that calls&nbsp;<i>sed</i>&nbsp;is easy if you remembered&nbsp;<a href="http://www.grymoire.com/Unix/Quote.html">my tutorial on the Unix quoting mechanism.</a>&nbsp;To review, you use the single quotes to turn quoting on and off. A simple shell script that uses&nbsp;<i>sed</i>&nbsp;to emulate grep is:&nbsp;</p>
<p>#!/bin/sh<br />
sed -n &#8216;s/&#8217;$1&#8242;/&amp;/p&#8217;</p>
<p>However &#8211; there is a problem with this script. If you have a space as an argument, the script would cause a syntax error A better version would protect from this happening:&nbsp;</p>
<p>#!/bin/sh<br />
sed -n &#8216;s/&#8217;&quot;$1&quot;&#8217;/&amp;/p&#8217;<br />
&nbsp;</p>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sedgrep.sed">sedgrep.sed</a><br />
If this was stored in a file called&nbsp;<i>sedgrep</i>, you could type</p>
<dl>
<dd>sedgrep &#8216;[A-Z][A-Z]&#8216; &lt;file</p>
<p>This would allow sed to act as the grep command.</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-23" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-23">Using sed in a shell here-is document</a></h1>
<p>You can use&nbsp;<i>sed</i>&nbsp;to prompt the user for some parameters and then create a file with those parameters filled in. You could create a file with dummy values placed inside it, and use&nbsp;<i>sed</i>&nbsp;to change those dummy values. A simpler way is to use the &quot;here is&quot; document, which uses part of the shell script as if it were standard input:</p>
<pre>
#!/bin/sh
echo -n 'what is the value? '
read value
sed  's/XXX/'$value'/' &lt;&lt;EOF
The value is XXX
EOF
</pre>
<p>&nbsp;</p>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_hereis.sed">sed_hereis.sed</a><br />
When executed, the script says:</p>
<dl>
<dd>what is the value?
</dd>
</dl>
<p>If you type in &quot;123,&quot; the next line will be:</p>
<dl>
<dd>The value is 123
</dd>
</dl>
<p>I admit this is a contrived example. &quot;Here is&quot; documents can have values evaluated without the use of sed. This example does the same thing:</p>
<dl>
<dd>#!/bin/sh<br />
echo -n &#8216;what is the value? &#8216;<br />
read value<br />
cat &lt;&lt;EOF<br />
The value is $value<br />
EOF
</dd>
</dl>
<p>However, combining &quot;here is&quot; documents with&nbsp;<i>sed</i>&nbsp;can be useful for some complex cases.&nbsp;<br />
Note that&nbsp;</p>
<p>sed &#8216;s/XXX/&#8217;$value&#8217;/&#8217; &lt;&lt;EOF</p>
<p>will give a syntax error if the user types a space. Better form would be to use&nbsp;</p>
<p>sed &#8216;s/XXX/&#8217;&quot;$value&quot;&#8217;/&#8217; &lt;&lt;EOF</p>
<p>&nbsp;</p>
<h1><a name="uh-24" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-24">Multiple commands and order of execution</a></h1>
<p>As we explore more of the commands of&nbsp;<i>sed</i>, the commands will become complex, and the actual sequence can be confusing. It&#8217;s really quite simple. Each line is read in. Each command, in order specified by the user, has a chance to operate on the input line. After the substitutions are made, the next command has a chance to operate on the same line, which may have been modified by earlier commands. If you ever have a question, the best way to learn what will happen is to create a small example. If a complex command doesn&#8217;t work, make it simpler. If you are having problems getting a complex script working, break it up into two smaller scripts and pipe the two scripts together.</p>
<p>&nbsp;</p>
<h1><a name="uh-25" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-25">Addresses and Ranges of Text</a></h1>
<p>You have only learned one command, and you can see how powerful&nbsp;<i>sed</i>&nbsp;is. However, all it is doing is a&nbsp;<i>grep</i>&nbsp;and substitute. That is, the substitute command is treating each line by itself, without caring about nearby lines. What would be useful is the ability to restrict the operation to certain lines. Some useful restrictions might be:</p>
<dl>
<dd></p>
<p>&nbsp;</p>
<ul>
<li>Specifying a line by its number.</li>
<li>Specifying a range of lines by number.</li>
<li>All lines containing a pattern.</li>
<li>All lines from the beginning of a file to a regular expression</li>
<li>All lines from a regular expression to the end of the file.</li>
<li>All lines between two regular expressions.</li>
</ul>
</dd>
</dl>
<p><i>Sed</i>&nbsp;can do all that and more. Every command in&nbsp;<i>sed</i>&nbsp;can be proceeded by an address, range or restriction like the above examples. The restriction or address immediately precedes the command:</p>
<dl>
<dd><i>restriction</i>&nbsp;<i>command</i>
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-26" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-26">Restricting to a line number</a></h1>
<p>The simplest restriction is a line number. If you wanted to delete the first number on line 3, just add a &quot;3&quot; before the command:</p>
<dl>
<dd>sed &#8217;3 s/[0-9][0-9]*//&#8217; &lt;file &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-27" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-27">Patterns</a></h1>
<p>Many Unix utilities like&nbsp;<i>vi</i>&nbsp;and&nbsp;<i>more</i>&nbsp;use a slash to search for a regular expression.&nbsp;<i>Sed</i>&nbsp;uses the same convention, provided you terminate the expression with a slash. To delete the first number on all lines that start with a &quot;#,&quot; use:</p>
<dl>
<dd>sed &#8216;/^#/ s/[0-9][0-9]*//&#8217;
</dd>
</dl>
<p>I placed a space after the &quot;/<i>expression</i>/&quot; so it is easier to read. It isn&#8217;t necessary, but without it the command is harder to fathom.&nbsp;<i>Sed</i>&nbsp;does provide a few extra options when specifying regular expressions. But I&#8217;ll discuss those later. If the expression starts with a backslash, the next character is the delimiter. To use a comma instead of a slash, use:</p>
<dl>
<dd>sed &#8216;\,^#, s/[0-9][0-9]*//&#8217;
</dd>
</dl>
<p>The main advantage of this feature is searching for slashes. Suppose you wanted to search for the string &quot;/usr/local/bin&quot; and you wanted to change it for &quot;/common/all/bin.&quot; You could use the backslash to escape the slash:</p>
<dl>
<dd>sed &#8216;/\/usr\/local\/bin/ s/\/usr\/local/\/common\/all/&#8217;
</dd>
</dl>
<p>It would be easier to follow if you used an underline instead of a slash as a search. This example uses the underline in both the search command and the substitute command:</p>
<dl>
<dd>sed &#8216;\_/usr/local/bin_ s_/usr/local_/common/all_&#8217;
</dd>
</dl>
<p>This illustrates why&nbsp;<i>sed</i>&nbsp;scripts get the reputation for obscurity. I could be perverse and show you the example that will search for all lines that start with a &quot;g,&quot; and change each &quot;g&quot; on that line to an &quot;s:&quot;</p>
<dl>
<dd>sed &#8216;/^g/s/g/s/g&#8217;
</dd>
</dl>
<p>Adding a space and using an underscore after the substitute command makes this&nbsp;<b>much</b>&nbsp;easier to read:</p>
<dl>
<dd>sed &#8216;/^g/ s_g_s_g&#8217;
</dd>
</dl>
<p>Er, I take that back. It&#8217;s hopeless. There is a lesson here: Use comments liberally in a&nbsp;<i>sed</i>&nbsp;script under SunOS. You may have to remove the comments to run the script under a different operating system, but you now know how to write a&nbsp;<i>sed</i>&nbsp;script to do that very easily! Comments are a Good Thing. You may have understood the script perfectly when you wrote it. But six months from now it could look like modem noise.</p>
<p>&nbsp;</p>
<h1><a name="uh-28" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-28">Ranges by line number</a></h1>
<p>You can specify a range on line numbers by inserting a comma between the numbers. To restrict a substitution to the first 100 lines, you can use:</p>
<dl>
<dd>sed &#8217;1,100 s/A/a/&#8217;
</dd>
</dl>
<p>If you know exactly how many lines are in a file, you can explicitly state that number to perform the substitution on the rest of the file. In this case, assume you used&nbsp;<i>wc</i>&nbsp;to find out there are 532 lines in the file:</p>
<dl>
<dd>sed &#8217;101,532 s/A/a/&#8217;
</dd>
</dl>
<p>An easier way is to use the special character &quot;$,&quot; which means the last line in the file.</p>
<dl>
<dd>sed &#8217;101,$ s/A/a/&#8217;
</dd>
</dl>
<p>The &quot;$&quot; is one of those conventions that mean &quot;last&quot; in utilities like&nbsp;<i>cat -e</i>,&nbsp;<i>vi</i>, and&nbsp;<i>ed</i>. &quot;cat -e&quot; Line numbers are cumulative if several files are edited. That is,</p>
<dl>
<dd>sed &#8217;200,300 s/A/a/&#8217; f1 f2 f3 &gt;new
</dd>
</dl>
<p>is the same as</p>
<dl>
<dd>cat f1 f2 f3 | sed &#8217;200,300 s/A/a/&#8217; &gt;new
</dd>
</dl>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-29" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-29">Ranges by patterns</a></h1>
<p>You can specify two regular expressions as the range. Assuming a &quot;#&quot; starts a comment, you can search for a keyword, remove all comments until you see the second keyword. In this case the two keywords are &quot;start&quot; and &quot;stop:&quot;</p>
<dl>
<dd>sed &#8216;/start/,/stop/ s/#.*//&#8217;
</dd>
</dl>
<p>The first pattern turns on a flag that tells&nbsp;<i>sed</i>&nbsp;to perform the substitute command on every line. The second pattern turns off the flag. If the &quot;start&quot; and &quot;stop&quot; pattern occurs twice, the substitution is done both times. If the &quot;stop&quot; pattern is missing, the flag is never turned off, and the substitution will be performed on every line until the end of the file.</p>
<p>You should know that if the &quot;start&quot; pattern is found, the substitution occurs on the same line that contains &quot;start.&quot; This turns on a switch, which is line oriented. That is, the next line is read and the substitute command is checked. If it contains &quot;stop&quot; the switch is turned off. Switches are line oriented, and not word oriented.</p>
<p>You can combine line numbers and regular expressions. This example will remove comments from the beginning of the file until it finds the keyword &quot;start:&quot;</p>
<dl>
<dd>sed -e &#8217;1,/start/ s/#.*//&#8217;
</dd>
</dl>
<p>This example will remove comments everywhere except the lines&nbsp;<b>between</b>&nbsp;the two keywords:</p>
<dl>
<dd>sed -e &#8217;1,/start/ s/#.*//&#8217; -e &#8216;/stop/,$ s/#.*//&#8217;
</dd>
</dl>
<p>The last example has a range that overlaps the &quot;/start/,/stop/&quot; range, as both ranges operate on the lines that contain the keywords. I will show you later how to restrict a command up to,&nbsp;<b>but not including</b>&nbsp;the line containing the specified pattern.</p>
<p>Before I start discussing the various commands, I should explain that some commands cannot operate on a range of lines. I will let you know when I mention the commands. In this next section I will describe three commands, one of which cannot operate on a range.</p>
<p>&nbsp;</p>
<h1><a name="uh-30" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-30">Delete with d</a></h1>
<p>Using ranges can be confusing, so you should expect to do some experimentation when you are trying out a new script. A useful command deletes every line that matches the restriction: &quot;d.&quot; If you want to look at the first 10 lines of a file, you can use:</p>
<dl>
<dd>sed &#8217;11,$ d&#8217; &lt;file&nbsp;
</dd>
</dl>
<p>which is similar in function to the&nbsp;<i>head</i>&nbsp;command. If you want to chop off the header of a mail message, which is everything up to the first blank line, use:</p>
<dl>
<dd>sed &#8217;1,/^$/ d&#8217; &lt;file
</dd>
</dl>
<p>You can duplicate the function of the&nbsp;<i>tail</i>&nbsp;command, assuming you know the length of a file.&nbsp;<i>Wc</i>&nbsp;can count the lines, and&nbsp;<i>expr</i>&nbsp;can subtract 10 from the number of lines. A Bourne shell script to look at the last 10 lines of a file might look like this:&nbsp;</p>
<p>#!/bin/sh<br />
#print last 10 lines of file<br />
# First argument is the filename<br />
lines=`wc -l $1 | awk &#8216;{print $1}&#8217; `<br />
start=`expr $lines &#8211; 10`<br />
sed &quot;1,$start d&quot; $1</p>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_tail.sh">sed_tail.sh</a><br />
The range for deletions can be regular expressions pairs to mark the begin and end of the operation. Or it can be a single regular expression. Deleting all lines that start with a &quot;#&quot; is easy:</p>
<dl>
<dd>sed &#8216;/^#/ d&#8217;&nbsp;
</dd>
</dl>
<p>Removing comments and blank lines takes two commands. The first removes every character from the &quot;#&quot; to the end of the line, and the second deletes all blank lines:</p>
<dl>
<dd>sed -e &#8216;s/#.*//&#8217; -e &#8216;/^$/ d&#8217;&nbsp;
</dd>
</dl>
<p>A third one should be added to remove all blanks and tabs immediately before the end of line:</p>
<dl>
<dd>sed -e &#8216;s/#.*//&#8217; -e &#8216;s/[ ^I]*$//&#8217; -e &#8216;/^$/ d&#8217;&nbsp;
</dd>
</dl>
<p>The character &quot;^I&quot; is a&nbsp;<i>CRTL-I</i>&nbsp;or tab character. You would have to explicitly type in the tab. Note the order of operations above, which is in that order for a very good reason. Comments might start in the middle of a line, with white space characters before them. Therefore comments are first removed from a line, potentially leaving white space characters that were before the comment. The second command removes all trailing blanks, so that lines that are now blank are converted to empty lines. The last command deletes empty lines. Together, the three commands remove all lines containing only comments, tabs or spaces.</p>
<p>This demonstrates the pattern space&nbsp;<i>sed</i>&nbsp;uses to operate on a line. The actual operation&nbsp;<i>sed</i>&nbsp;uses is:</p>
<dl>
<dd></p>
<p>&nbsp;</p>
<ul>
<li>Copy the input line into the pattern space.</li>
<li>Apply the first&nbsp;<br />
    <i>sed</i>&nbsp;command on the pattern space, if the address restriction is true.</li>
<li>Repeat with the next sed expression, again<br />
    operating on the pattern space.</li>
<li>When the last operation is performed, write out the pattern space<br />
    and read in the next line from the input file.</li>
</ul>
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-31" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-31">Printing with p</a></h1>
<p>Another useful command is the print command: &quot;p.&quot; If&nbsp;<i>sed</i>&nbsp;wasn&#8217;t started with an &quot;-n&quot; option, the &quot;p&quot; command will duplicate the input. The command</p>
<dl>
<dd>sed &#8216;p&#8217;
</dd>
</dl>
<p>will duplicate every line. If you wanted to double every empty line, use:</p>
<dl>
<dd>sed &#8216;/^$/ p&#8217;
</dd>
</dl>
<p>Adding the &quot;-n&quot; option turns off printing unless you request it. Another way of duplicating&nbsp;<i>head</i>&#8216;s functionality is to print only the lines you want. This example prints the first 10 lines:</p>
<dl>
<dd>sed -n &#8217;1,10 p&#8217; &lt;file
</dd>
</dl>
<p><i>Sed</i>&nbsp;can act like&nbsp;<i>grep</i>&nbsp;by combining the print operator to function on all lines that match a regular expression:</p>
<dl>
<dd>sed -n &#8216;/match/ p&#8217;&nbsp;
</dd>
</dl>
<p>which is the same as:</p>
<dl>
<dd>grep match
</dd>
</dl>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-32" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-32">Reversing the restriction with !</a></h1>
<p>Sometimes you need to perform an action on every line except those that match a regular expression, or those outside of a range of addresses. The &quot;!&quot; character, which often means&nbsp;<i>not</i>&nbsp;in Unix utilities, inverts the address restriction. You remember that</p>
<dl>
<dd>sed -n &#8216;/match/ p&#8217;
</dd>
</dl>
<p>acts like the&nbsp;<i>grep</i>&nbsp;command. The &quot;-v&quot; option to&nbsp;<i>grep</i>&nbsp;prints all lines that don&#8217;t contain the pattern.&nbsp;<i>Sed</i>&nbsp;can do this with</p>
<dl>
<dd>sed -n &#8216;/match/ !p&#8217; &lt;/tmp/b
</dd>
</dl>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-33" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-33">Relationships between d, p, and !</a></h1>
<p>As you may have noticed, there are often several ways to solve the same problem with&nbsp;<i>sed</i>. This is because&nbsp;<i>print</i>&nbsp;and&nbsp;<i>delete</i>&nbsp;are opposite functions, and it appears that &quot;!p&quot; is similar to &quot;d,&quot; while &quot;!d&quot; is similar to &quot;p.&quot; I wanted to test this, so I created a 20 line file, and tried every different combination. The following table, which shows the results, demonstrates the difference:</p>
<pre>
Relations between d, p, and !
  Sed	   Range   Command   Results
  --------------------------------------------------------
  sed -n   1,10	   p	     Print first 10 lines
  sed -n   11,$	   !p	     Print first 10 lines
  sed	   1,10	   !d	     Print first 10 lines
  sed	   11,$	   d	     Print first 10 lines
  --------------------------------------------------------
  sed -n   1,10	   !p	     Print last 10 lines
  sed -n   11,$	   p	     Print last 10 lines
  sed	   1,10	   d	     Print last 10 lines
  sed	   11,$	   !d	     Print last 10 lines
  --------------------------------------------------------
  sed -n   1,10	   d	     Nothing printed
  sed -n   1,10	   !d	     Nothing printed
  sed -n   11,$	   d	     Nothing printed
  sed -n   11,$	   !d	     Nothing printed
  --------------------------------------------------------
  sed	   1,10	   p	     Print first 10 lines twice,
			     Then next 10 lines once
  sed	   11,$	   !p	     Print first 10 lines twice,
			     Then last 10 lines once
  --------------------------------------------------------
  sed	   1,10	   !p	     Print first 10 lines once,
			     Then last 10 lines twice
  sed	   11,$	   p	     Print first 10 lines once,
			     then last 10 lines twice</pre>
<p>This table shows that the following commands are identical:</p>
<dl>
<dd>sed -n &#8217;1,10 p&#8217;<br />
sed -n &#8217;11,$ !p&#8217;<br />
sed &#8217;1,10 !d&#8217;<br />
sed &#8217;11,$ d&#8217;
</dd>
</dl>
<p>It also shows that the &quot;!&quot; command &quot;inverts&quot; the address range, operating on the other lines.</p>
<p>&nbsp;</p>
<h1><a name="uh-34" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-34">The q or quit command</a></h1>
<p>There is one more simple command that can restrict the changes to a set of lines. It is the &quot;q&quot; command: quit. the third way to duplicate the head command is:</p>
<dl>
<dd>sed &#8217;11 q&#8217;
</dd>
</dl>
<p>which quits when the eleventh line is reached. This command is most useful when you wish to abort the editing after some condition is reached.</p>
<p>The &quot;q&quot; command is the one command that does not take a range of addresses. Obviously the command</p>
<dl>
<dd>sed &#8217;1,10 q&#8217;
</dd>
</dl>
<p>cannot quit 10 times. Instead</p>
<dl>
<dd>sed &#8217;1 q&#8217;
</dd>
</dl>
<p>or</p>
<dl>
<dd>sed &#8217;10 q&#8217;
</dd>
</dl>
<p>is correct.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-35" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-35">Grouping with { and }</a></h1>
<p>The curly braces, &quot;{&quot; and &quot;},&quot; are used to group the commands.</p>
<p>Hardly worth the build up. All that prose and the solution is just matching squigqles. Well, there is one complication. Since each&nbsp;<i>sed</i>&nbsp;command must start on its own line, the curly braces and the nested&nbsp;<i>sed</i>commands must be on separate lines.</p>
<p>Previously, I showed you how to remove comments starting with a &quot;#.&quot; If you wanted to restrict the removal to lines between special &quot;begin&quot; and &quot;end&quot; key words, you could use:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
# This is a Borne shell script that removes #-type comments
# between 'begin' and 'end' words.
sed -n '
	/begin/,/end/ {
	     s/#.*//
	     s/[ ^I]*$//
	     /^$/ d
	     p
	}
'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_begin_end.sh">sed_begin_end.sh</a><br />
These braces can be nested, which allow you to combine address ranges. You could perform the same action as before, but limit the change to the first 100 lines:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
# This is a Borne shell script that removes #-type comments
# between 'begin' and 'end' words.
sed -n '
	1,100 {
		/begin/,/end/ {
		     s/#.*//
		     s/[ ^I]*$//
		     /^$/ d
		     p
		}
	}
'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_begin_end1.sh">sed_begin_end1.sh</a><br />
You can place a &quot;!&quot; before a set of curly braces. This inverts the address, which removes comments from all lines&nbsp;<b>except</b>&nbsp;those between the two reserved words:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
	/begin/,/end/ !{
	     s/#.*//
	     s/[ ^I]*$//
	     /^$/ d
	     p
	}
'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_begin_end2.sh">sed_begin_end2.sh</a></p>
<p>&nbsp;</p>
<h1><a name="uh-36" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-36">Writing a file with the &#8216;w&#8217; command</a></h1>
<p>You may remember that the substitute command can write to a file:</p>
<dl>
<dd>sed -n &#8216;s/^[0-9]*[02468] /&amp;/w even&#8217; &lt;file&nbsp;
</dd>
</dl>
<p>I used the &quot;&amp;&quot; in the replacement part of the substitution command so that the line would not be changed. A simpler example is to use the &quot;w&quot; command, which has the same syntax as the &quot;w&quot; flag in the substitute command:</p>
<dl>
<dd>sed -n &#8216;/^[0-9]*[02468]/ w even&#8217; &lt;file
</dd>
</dl>
<p>Remember &#8211; only one space must follow the command. Anything else will be considered part of the file name. The &quot;w&quot; command also has the same limitation as the &quot;w&quot; flag: only 10 files can be opened in&nbsp;<i>sed</i>.</p>
<p>&nbsp;</p>
<h1><a name="uh-37" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-37">Reading in a file with the &#8216;r&#8217; command</a></h1>
<p>There is also a command for reading files. The command</p>
<dl>
<dd>sed &#8216;$r end&#8217; &lt;in&gt;out
</dd>
</dl>
<p>will append the file &quot;end&quot; at the end of the file (address &quot;$).&quot; The following will insert a file after the line with the word &quot;INCLUDE:&quot;</p>
<dl>
<dd>sed &#8216;/INCLUDE/ r file&#8217; &lt;in &gt;out
</dd>
</dl>
<p>You can use the curly braces to delete the line having the &quot;INCLUDE&quot; command on it:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '/INCLUDE/ {
	r file
	d
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_include.sh">sed_include.sh</a></p>
<p>The order of the delete command &quot;d&quot; and the read file command &quot;r&quot; is important. Change the order and it will not work. There are two subtle actions that prevent this from working. The first is the &quot;r&quot; command writes the file to the output stream. The file is not inserted into the pattern space, and therefore cannot be modified by any command. Therefore the delete command does not affect the data read from the file.</p>
<p>The other subtlety is the &quot;d&quot; command deletes the current data in the pattern space. Once all of the data is deleted, it does make sense that no other action will be attempted. Therefore a &quot;d&quot; command executed in a curly brace also aborts all further actions. As an example, the substitute command below is never executed:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
# this example is WRONG
sed -e '1 {
	d
	s/.*//
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_bad_example.sh">sed_bad_example.sh</a></p>
<p>The earlier example is a crude version of the C preprocessor program. The file that is included has a predetermined name. It would be nice if&nbsp;<i>sed</i>&nbsp;allowed a variable (e.g &quot;\1)&quot; instead of a fixed file name. Alas,<i>sed</i>&nbsp;doesn&#8217;t have this ability. You could work around this limitation by creating&nbsp;<i>sed</i>&nbsp;commands on the fly, or by using shell quotes to pass variables into the&nbsp;<i>sed</i>&nbsp;script. Suppose you wanted to create a command that would include a file like&nbsp;<i>cpp</i>, but the filename is an argument to the script. An example of this script is:</p>
<dl>
<dd>% include &#8216;sys/param.h&#8217; &lt;file.c &gt;file.c.new
</dd>
</dl>
<p>A shell script to do this would be:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
# watch out for a '/' in the parameter
# use alternate search delimiter
sed -e '\_#INCLUDE &lt;'&quot;$1&quot;'&gt;_{
	r '&quot;$1&quot;'
	d
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_include1.sh">sed_include1.sh</a></p>
<p>&nbsp;</p>
<h1><a name="uh-38" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-38">SunOS and the # Comment Command</a></h1>
<p>As we dig deeper into&nbsp;<i>sed</i>, comments will make the commands easier to follow. Most versions of&nbsp;<i>sed</i>&nbsp;only allow one line as a comment, and it must be the first line. SunOS allows more than one comment, and these comments don&#8217;t have to be first. The last example could be:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
# watch out for a '/' in the parameter
# use alternate search delimiter
sed -e '\_#INCLUDE &lt;'&quot;$1&quot;'&gt;_{

	# read the file
	r '&quot;$1&quot;'

	# delete any characters in the pattern space
	# and read the next line in
	d
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_include2.sh">sed_include2.sh</a></p>
<p>&nbsp;</p>
<h1><a name="uh-39" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-39">Adding, Changing, Inserting new lines</a></h1>
<p><i>Sed</i>&nbsp;has three commands used to add new lines to the output stream. Because an entire line is added, the new line is on a line by itself to emphasize this. There is no option, an entire line is used, and it must be on its own line. If you are familiar with many unix utilities, you would expect&nbsp;<i>sed</i>&nbsp;to use a similar convention: lines are continued by ending the previous line with a &quot;\&quot;. The syntax to these commands is finicky, like the &quot;r&quot; and &quot;w&quot; commands.</p>
<p>&nbsp;</p>
<h1><a name="uh-40" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-40">Append a line with &#8216;a&#8217;</a></h1>
<p>The &quot;a&quot; command appends a line after the range or pattern. This example will add a line after every line with &quot;WORD:&quot;&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
/WORD/ a\
Add this line after every line with WORD
'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_add_line_after_word.sh">sed_add_line_after_word.sh</a></p>
<p>You could eliminate two lines in the shell script if you wish:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '/WORD/ a\
Add this line after every line with WORD'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_add_line_after_word1.sh">sed_add_line_after_word1.sh</a></p>
<p>I prefer the first form because it&#8217;s easier to add a new command by adding a new line and because the intent is clearer. There must not be a space after the &quot;\&quot;.</p>
<p>&nbsp;</p>
<h1><a name="uh-41" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-41">Insert a line with &#8216;i&#8217;</a></h1>
<p>You can insert a new line before the pattern with the &quot;i&quot; command:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
/WORD/ i\
Add this line before every line with WORD
'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_add_line_before_word.sh">sed_add_line_before_word.sh</a></p>
<p>&nbsp;</p>
<h1><a name="uh-42" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-42">Change a line with &#8216;c&#8217;</a></h1>
<p>You can change the current line with a new line.&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
/WORD/ c\
Replace the current line with the line
'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_change_line.sh">sed_change_line.sh</a></p>
<p>A &quot;d&quot; command followed by a &quot;a&quot; command won&#8217;t work, as I discussed earlier. The &quot;d&quot; command would terminate the current actions. You can combine all three actions using curly braces:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
/WORD/ {
i\
Add this line before
a\
Add this line after
c\
Change the line to this one
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_insert_append_change.sh">sed_insert_append_change.sh</a></p>
<p>&nbsp;</p>
<h1><a name="uh-43" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-43">Leading tabs and spaces in a sed script</a></h1>
<p><i>Sed</i>&nbsp;ignores leading tabs and spaces in all commands. However these white space characters may or may not be ignored if they start the text following a &quot;a,&quot; &quot;c&quot; or &quot;i&quot; command. In SunOS, both &quot;features&quot; are available. The Berkeley (and Linux) style sed is in /usr/bin, and the AT&amp;T version (System V) is in /usr/5bin/.</p>
<p>To elaborate, the&nbsp;<b>/usr/bin/sed</b>&nbsp;command retains white space, while the&nbsp;<b>/usr/5bin/sed</b>&nbsp;strips off leading spaces. If you want to keep leading spaces, and not care about which version of&nbsp;<i>sed</i>&nbsp;you are using, put a &quot;\&quot; as the first character of the line:</p>
<dl>
<dd>
<pre>
#!/bin/sh
sed '
	a\
\	This line starts with a tab
'
</pre>
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-44" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-44">Adding more than one line</a></h1>
<p>All three commands will allow you to add more than one line. Just end each line with a &quot;\:&quot;</p>
<dl>
<dd>#!/bin/sh<br />
sed &#8216;<br />
/WORD/ a\<br />
Add this line\<br />
This line\<br />
And this line<br />
&#8216;
</dd>
</dl>
<p>&nbsp;</p>
<h1><a name="uh-45" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-45">Adding lines and the pattern space</a></h1>
<p>I have mentioned the pattern space before. Most commands operate on the pattern space, and subsequent commands may act on the results of the last modification. The three previous commands, like the read file command, add the new lines to the output stream, bypassing the pattern space.</p>
<p>&nbsp;</p>
<h1><a name="uh-46" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-46">Address ranges and the above commands</a></h1>
<p>You may remember in my last tutorial I warned you that some commands can take a range of lines, and others cannot. To be precise, the commands &quot;a,&quot; &quot;i,&quot; &quot;r,&quot; and &quot;q&quot; will not take a range like &quot;1,100&quot; or &quot;/begin/,/end/.&quot; The documentation states that the read command can take a range, but I get an error when I try this. The &quot;c&quot; or change command allows this, and it will let you change several lines into one:</p>
<dl>
<dd>#!/bin/sh<br />
sed &#8216;<br />
/begin/,/end/ c\<br />
***DELETED***<br />
&#8216;
</dd>
</dl>
<p>If you need to do this, you can use the curly braces, as that will let you perform the operation on every line:</p>
<dl>
<dd>
<pre>
#!/bin/sh
# add a blank line after every line
sed '1,$ {
	a\

}'
</pre>
</dd>
</dl>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-47" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-47">Multi-Line Patterns</a></h1>
<p>&nbsp;</p>
<p>Most UNIX utilities are line oriented. Regular expressions are line oriented. Searching for patterns that covers more than one line is not an easy task. (Hint: It will be very shortly.)</p>
<p><i>Sed</i>&nbsp;reads in a line of text, performs commands which may modify the line, and outputs modification if desired. The main loop of a&nbsp;<i>sed</i>&nbsp;script looks like this:</p>
<p>&nbsp;</p>
<ol>
<li>The next line is read from the input file and places in the pattern space. If the end of file is found, and if there are additional files to read, the current file is closed, the next file is opened, and the first line of the new file is placed into the pattern space.</li>
<li>The line count is incremented by one. Opening a new file does not reset this number.</li>
<li>Each&nbsp;<i>sed</i>&nbsp;command is examined. If there is a restriction placed on the command, and the current line in the pattern space meets that restriction, the command is executed. Some commands, like &quot;n&quot; or &quot;d&quot; cause&nbsp;<i>sed</i>&nbsp;to go to the top of the loop. The &quot;q&quot; command causes&nbsp;<i>sed</i>&nbsp;to stop. Otherwise the next command is examined.</li>
<li>After all of the commands are examined, the pattern space is output unless&nbsp;<i>sed</i>&nbsp;has the optional &quot;-n&quot; argument.</li>
</ol>
<p>The restriction before the command determines if the command is executed. If the restriction is a pattern, and the operation is the delete command, then the following will delete all lines that have the pattern:</p>
<dl>
<dd>/PATTERN/ d
</dd>
</dl>
<p>If the restriction is a pair of numbers, then the deletion will happen if the line number is equal to the first number or greater than the first number and less than or equal to the last number:</p>
<dl>
<dd>10,20 d
</dd>
</dl>
<p>If the restriction is a pair of patterns, there is a variable that is kept for each of these pairs. If the variable is false and the first pattern is found, the variable is made true. If the variable is true, the command is executed. If the variable is true, and the last pattern is on the line, after the command is executed the variable is turned off:</p>
<dl>
<dd>/begin/,/end/ d
</dd>
</dl>
<p>Whew! That was a mouthful. If you have read carefully up to here, you should have breezed through this. You may want to refer back, because I covered several subtle points. My choice of words was deliberate. It covers some unusual cases, like:</p>
<dl>
<dd># what happens if the second number<br />
# is less than the first number?<br />
sed -n &#8217;20,1 p&#8217; file
</dd>
</dl>
<p>and</p>
<dl>
<dd># generate a 10 line file with line numbers<br />
# and see what happens when two patterns overlap<br />
yes | head -10 | cat -n | \<br />
sed -n -e &#8216;/1/,/7/ p&#8217; -e &#8216;/5/,/9/ p&#8217;
</dd>
</dl>
<p>Enough mental punishment. Here is another review, this time in a table format. Assume the input file contains the following lines:</p>
<dl>
<dd>AB<br />
CD<br />
EF<br />
GH<br />
IJ
</dd>
</dl>
<p>When&nbsp;<i>sed</i>&nbsp;starts up, the first line is placed in the pattern space. The next line line is &quot;CD.&quot; The operations of the &quot;n,&quot; &quot;d,&quot; and &quot;p&quot; commands can be summarized as:</p>
<pre>
+----------------+---------+------------------------------------------+
|Pattern   Next	 | Command | Output	       New Pattern   New Next |
|Space	   Input |	   |		       Space	     Input    |
+----------------+---------+------------------------------------------+
|AB	   CD	 | n	   | &lt;default&gt;   	CD	     EF	      |
|AB	   CD	 | d	   | -		       CD	     EF	      |
|AB	   CD	 | p	   | AB		       CD	     EF	      |
+----------------+---------+------------------------------------------+</pre>
<p>The &quot;n&quot; command may or may not generate output depending upon the existence of the &quot;-n&quot; flag.</p>
<p>That review is a little easier to follow, isn&#8217;t it? Before I jump into multi-line patterns, I wanted to cover three more commands:</p>
<p>&nbsp;</p>
<h1><a name="uh-48" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-48">Print line number with =</a></h1>
<p>The &quot;=&quot; command prints the current line number to standard output. One way to find out the line numbers that contain a pattern is to use:</p>
<dl>
<dd># add line numbers first,&nbsp;<br />
# then use grep,&nbsp;<br />
# then just print the number<br />
cat -n file | grep &#8216;PATTERN&#8217; | awk &#8216;{print $1}&#8217;
</dd>
</dl>
<p>The&nbsp;<i>sed</i>&nbsp;solution is:</p>
<dl>
<dd>sed -n &#8216;/PATTERN/ =&#8217; file
</dd>
</dl>
<p>&nbsp;</p>
<p>Earlier I used the following to find the number of lines in a file</p>
<dl>
<dd>#!/bin/sh<br />
lines=`wc -l file | awk &#8216;{print $1}&#8217; `
</dd>
</dl>
<p>Using the &quot;=&quot; command can simplify this:</p>
<dl>
<dd>#!/bin/sh<br />
lines=`sed -n &#8216;$=&#8217; file `
</dd>
</dl>
<p>The &quot;=&quot; command only accepts one address, so if you want to print the number for a range of lines, you must use the curly braces:</p>
<dl>
<dd>#!/bin/sh<br />
# Just print the line numbers&nbsp;<br />
sed -n &#8216;/begin/,/end/ {<br />
=<br />
d<br />
}&#8217; file
</dd>
</dl>
<p>Since the &quot;=&quot; command only prints to standard output, you cannot print the line number on the same line as the pattern. You need to edit multi-line patterns to do this.</p>
<p>&nbsp;</p>
<h1><a name="uh-49" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-49">Transform with y</a></h1>
<p>If you wanted to change a word from lower case to upper case, you could write 26 character substitutions, converting &quot;a&quot; to &quot;A,&quot; etc.&nbsp;<i>Sed</i>&nbsp;has a command that operates like the&nbsp;<i>tr</i>&nbsp;program. It is called the &quot;y&quot; command. For instance, to change the letters &quot;a&quot; through &quot;f&quot; into their upper case form, use:</p>
<dl>
<dd>sed &#8216;y/abcdef/ABCDEF/&#8217; file
</dd>
</dl>
<p>I could have used an example that converted all 26 letters into upper case, and while this column covers a broad range of topics, the &quot;column&quot; prefers a narrower format.</p>
<p>If you wanted to convert a line that contained a hexadecimal number (e.g. 0x1aff) to upper case (0x1AFF), you could use:</p>
<dl>
<dd>sed &#8216;/0x[0-9a-zA-Z]*/ y/abcdef/ABCDEF&#8217; file
</dd>
</dl>
<p>This works fine if there are only numbers in the file. If you wanted to change the second word in a line to upper case, you are out of luck &#8211; unless you use multi-line editing. (Hey &#8211; I think there is some sort of theme here!)</p>
<p>&nbsp;</p>
<h1><a name="uh-50" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-50">Displaying control characters with a l</a></h1>
<p>The &quot;l&quot; command prints the current pattern space. It is therefore useful in debugging&nbsp;<i>sed</i>&nbsp;scripts. It also converts unprintable characters into printing characters by outputting the value in octal preceded by a &quot;\&quot; character. I found it useful to print out the current pattern space, while probing the subtleties of&nbsp;<i>sed</i>.</p>
<p>&nbsp;</p>
<h1><a name="uh-51" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-51">Working with Multiple Lines</a></h1>
<p>There are three new commands used in multiple-line patterns: &quot;N,&quot; &quot;D,&quot; and &quot;P.&quot; I will explain their relation to the matching &quot;n,&quot; &quot;d,&quot; and &quot;p&quot; single-line commands.</p>
<p>The &quot;n&quot; command will print out the current pattern space (unless the &quot;-n&quot; flag is used), empty the current pattern space, and read in the next line of input. The &quot;N&quot; command does&nbsp;<b>not</b>&nbsp;print out the current pattern space and does&nbsp;<b>not</b>&nbsp;empty the pattern space. It reads in the next line, but appends a new line character along with the input line itself to the pattern space.</p>
<p>The &quot;d&quot; command deleted the current pattern space, reads in the next line, puts the new line into the pattern space, and aborts the current command, and starts execution at the first&nbsp;<i>sed</i>&nbsp;command. This is called starting a new &quot;cycle.&quot; The &quot;D&quot; command deletes the first portion of the pattern space, up to the new line character, leaving the rest of the pattern alone. Like &quot;d,&quot; it stops the current command and starts the command cycle over again. However, it will not print the current pattern space. You must print it yourself, a step earlier. If the &quot;D&quot; command is executed with a group of other commands in a curly brace, commands after the &quot;D&quot; command are ignored. The next group of&nbsp;<i>sed</i>&nbsp;commands is executed, unless the pattern space is emptied. If this happens, the cycle is started from the top and a new line is read.</p>
<p>The &quot;p&quot; command prints the entire pattern space. The &quot;P&quot; command only prints the first part of the pattern space, up to the NEWLINE character.</p>
<p>Some examples might demonstrate &quot;N&quot; by itself isn&#8217;t very useful. the filter</p>
<dl>
<dd>sed -e &#8216;N&#8217;
</dd>
</dl>
<p>doesn&#8217;t modify the input stream. Instead, it combines the first and second line, then prints them, combines the third and fourth line, and prints them, etc. It does allow you to use a new &quot;anchor&quot; character: &quot;\n.&quot; This matches the new line character that separates multiple lines in the pattern space. If you wanted to search for a line that ended with the character &quot;#,&quot; and append the next line to it, you could use</p>
<dl>
<dd>
<pre>
#!/bin/sh
sed '
# look for a &quot;#&quot; at the end of the line
/#$/ {
# Found one - now read in the next line
	N
# delete the &quot;#&quot; and the new line character,
	s/#\n//
}' file
</pre>
</dd>
</dl>
<p>You could search for two lines containing &quot;ONE&quot; and &quot;TWO&quot; and only print out the two consecutive lines:</p>
<dl>
<dd>
<pre>
#!/bin/sh
sed -n '
/ONE/ {
# found &quot;ONE&quot; - read in next line
	N
# look for &quot;TWO&quot; on the second line
# and print if there.
	/\n.*TWO/ p
}' file
</pre>
</dd>
</dl>
<p>The next example would delete everything between &quot;ONE&quot; and &quot;TWO:&quot;</p>
<dl>
<dd>
<pre>
#!/bin/sh
sed '
/ONE/ {
# append a line
	N
# search for TWO on the second line
	/\n.*TWO/ {
# found it - now edit making one line
		s/ONE.*\n.*TWO/ONE TWO/
	}
}' file
</pre>
</dd>
</dl>
<p>You can either search for a particular pattern on two consecutive lines, or you can search for two consecutive words that may be split on a line boundary. The next example will look for two words which are either on the same line or one is on the end of a line and the second is on the beginning of the next line. If found, the first word is deleted:</p>
<dl>
<dd>
<pre>
#!/bin/sh
sed '
/ONE/ {
# append a line
	N
# &quot;ONE TWO&quot; on same line
	s/ONE TWO/TWO/
# &quot;ONE
# TWO&quot; on two consecutive lines
	s/ONE\nTWO/TWO/
	}
}' file
</pre>
</dd>
</dl>
<p>&nbsp;</p>
<p>Let&#8217;s use the<br />
&quot;D&quot; command, and if we find a line containing<br />
&quot;TWO&quot; immediately after a line containing<br />
&quot;ONE,&quot; then delete the first line:</p>
<p>&nbsp;</p>
<pre>
#!/bin/sh
sed '
/ONE/ {
# append a line
	N
# if TWO found, delete the first line
	/\n.*TWO/ D
}' file
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_delete_line_after_word.sh">sed_delete_line_after_word.sh</a></p>
<p>If we wanted to print the first line instead of deleting it, and not print every other line, change the &quot;D&quot; to a &quot;P&quot; and add a &quot;-n&quot; as an argument to&nbsp;<i>sed</i>:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed -n '
# by default - do not print anything
/ONE/ {
# append a line
	N
# if TWO found, print the first line
	/\n.*TWO/ P
}' file
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_print_line_after_word.sh">sed_print_line_after_word.sh</a></p>
<p>It is very common to combine all three multi-line commands. The typical order is &quot;N,&quot; &quot;P&quot; and lastly &quot;D.&quot; This one will delete everything between &quot;ONE&quot; and &quot;TWO&quot; if they are on one or two consecutive lines:<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
/ONE/ {
# append the next line
	N
# look for &quot;ONE&quot; followed by &quot;TWO&quot;
	/ONE.*TWO/ {
#	delete everything between
		s/ONE.*TWO/ONE TWO/
#	print
		P
#	then delete the first line
		D
	}
}' file
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_delete_between_two_words.sh">sed_delete_between_two_words.sh</a></p>
<p>Earlier I talked about the &quot;=&quot; command, and using it to add line numbers to a file. You can use two invocations of&nbsp;<i>sed</i>&nbsp;to do this (although it is possible to do it with one, but that must wait until next section. The first&nbsp;<i>sed</i>&nbsp;command will output a line number on one line, and then print the line on the next line. The second invocation of&nbsp;<i>sed</i>&nbsp;will merge the two lines together:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '=' file | \
sed '{
	N
	s/\n/ /
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_merge_two_lines.sh">sed_merge_two_lines.sh</a></p>
<p>If you find it necessary, you can break one line into two lines, edit them, and merge them together again. As an example, if you had a file that had a hexadecimal number followed by a word, and you wanted to convert the first word to all upper case, you can use the &quot;y&quot; command, but you must first split the line into two lines, change one of the two, and merge them together. That is, a line containing</p>
<dl>
<dd>0x1fff table2
</dd>
</dl>
<p>will be changed into two lines:</p>
<dl>
<dd>0x1fff<br />
table2
</dd>
</dl>
<p>and the first line will be converted into upper case. I will use&nbsp;<i>tr</i>&nbsp;to convert the space into a new line:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
tr ' ' '\012' file|
sed ' {
	y/abcdef/ABCDEF/
	N
	s/\n/ /
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_split.sh">sed_split.sh</a></p>
<p>It isn&#8217;t obvious, but&nbsp;<i>sed</i>&nbsp;could be used instead of&nbsp;<i>tr</i>. You can embed a new line in a substitute command, but you must escape it with a backslash. It is unfortunate that you must use &quot;\n&quot; in the left side of a substitute command, and an embedded new line in the right hand side. Heavy sigh. Here is the example:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
s/ /\
/' | \
sed ' {
	y/abcdef/ABCDEF/
	N
	s/\n/ /
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_split_merge.sh">sed_split_merge.sh</a></p>
<p>Sometimes I add a special character as a marker, and look for that character in the input stream. When found, it indicates the place a blank used to be. A backslash is a good character, except it must be escaped with a backslash, and makes the&nbsp;<i>sed</i>&nbsp;script obscure. Save it for that guy who keeps asking dumb questions. The&nbsp;<i>sed</i>&nbsp;script to change a blank into a &quot;\&quot; following by a new line would be:&nbsp;</p>
<p>#!/bin/sh<br />
sed &#8216;s/ /\\\<br />
/&#8217; file</p>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_addslash_before_blank.sh">sed_addslash_before_blank.sh</a></p>
<p>Yeah. That&#8217;s the ticket. Or use the C shell and really confuse him!&nbsp;</p>
<p>#!/bin/csh -f<br />
sed &#8216;\<br />
s/ /\\\\<br />
/&#8217; file</p>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_addslash_before_blank.csh">sed_addslash_before_blank.csh</a></p>
<p>A few more examples of that, and he&#8217;ll never ask you a question again! I think I&#8217;m getting carried away. I&#8217;ll summarize with a chart that covers the features we&#8217;ve talked about:</p>
<pre>
+----------------+---------+------------------------------------------+
|Pattern   Next	 | Command | Output	       New Pattern   New Next |
|Space	   Input |	   |		       Space	     Input    |
+----------------+---------+------------------------------------------+
|AB	   CD	 | n	   | &lt;default&gt;	  	 CD	     EF	      |
|AB	   CD	 | N	   | -		       AB\nCD	     EF	      |
|AB	   CD	 | d	   | -		       CD	     EF	      |
|AB	   CD	 | D	   | -		       CD	     EF	      |
|AB	   CD	 | p	   | AB		       CD	     EF	      |
|AB	   CD	 | P	   | AB		       CD	     EF	      |
+----------------+---------+------------------------------------------+
|AB\nCD	   EF	 | n	   | &lt;default&gt; 		  EF	     GH	      |
|AB\nCD	   EF	 | N	   | -		       AB\nCD\nEF    GH	      |
|AB\nCD	   EF	 | d	   | -		       EF	     GH	      |
|AB\nCD	   EF	 | D	   | -		       CD	     EF	      |
|AB\nCD	   EF	 | p	   | AB\nCD	       AB\nCD	     EF	      |
|AB\nCD	   EF	 | P	   | AB		       AB\nCD	     EF	      |
+----------------+---------+------------------------------------------+</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-nl" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-nl">Using newlines in sed scripts</a></h1>
<p>Occasionally one wishes to use a new line character in a sed script. Well, this has some subtle issues here. If one wants to search for a new line, one has to use &quot;\n.&quot; Here is an example where you search for a phrase, and delete the new line character after that phrase &#8211; joining two lines together.</p>
<pre>
(echo a;echo x;echo y) | sed '/x$/ {
N
s:x\n:x:
}'
</pre>
<p>which generates</p>
<pre>
a
xy
</pre>
<p>However, if you are inserting a new line, don&#8217;t use &quot;\n&quot; &#8211; instead insert a literal new line character:</p>
<pre>
(echo a;echo x;echo y) | sed 's:x:X\
:'
</pre>
<p>generates</p>
<pre>
a
X

y
</pre>
<p>&nbsp;</p>
<h1><a name="uh-52" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-52">The Hold Buffer</a></h1>
<p>So far we have talked about three concepts of&nbsp;<i>sed</i>: (1) The input stream or data before it is modified, (2) the output stream or data after it has been modified, and (3) the pattern space, or buffer containing characters that can be modified and send to the output stream.</p>
<p>There is one more &quot;location&quot; to be covered: the&nbsp;<i>hold buffer</i>&nbsp;or&nbsp;<i>hold space</i>. Think of it as a spare pattern buffer. It can be used to &quot;copy&quot; or &quot;remember&quot; the data in the pattern space for later. There are five commands that use the hold buffer.</p>
<p>&nbsp;</p>
<h1><a name="uh-53" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-53">Exchange with x</a></h1>
<p>The &quot;x&quot; command eXchanges the pattern space with the hold buffer. By itself, the command isn&#8217;t useful. Executing the&nbsp;<i>sed</i>&nbsp;command</p>
<dl>
<dd>sed &#8216;x&#8217;
</dd>
</dl>
<p>as a filter adds a blank line in the front, and deletes the last line. It looks like it didn&#8217;t change the input stream significantly, but the&nbsp;<i>sed</i>&nbsp;command is modifying every line.</p>
<p>The hold buffer starts out containing a blank line. When the &quot;x&quot; command modifies the first line, line 1 is saved in the hold buffer, and the blank line takes the place of the first line. The second &quot;x&quot; command exchanges the second line with the hold buffer, which contains the first line. Each subsequent line is exchanged with the preceding line. The last line is placed in the hold buffer, and is not exchanged a second time, so it remains in the hold buffer when the program terminates, and never gets printed. This illustrates that care must be taken when storing data in the hold buffer, because it won&#8217;t be output unless you explicitly request it.</p>
<p>&nbsp;</p>
<h1><a name="uh-54" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-54">Example of Context Grep</a></h1>
<p>One use of the hold buffer is to remember previous lines. An example of this is a utility that acts like&nbsp;<i>grep</i>&nbsp;as it shows you the lines that match a pattern. In addition, it shows you the line before and after the pattern. That is, if line 8 contains the pattern, this utility would print lines 7, 8 and 9.</p>
<p>One way to do this is to see if the line has the pattern. If it does not have the pattern, put the current line in the hold buffer. If it does, print the line in the hold buffer, then the current line, and then the next line. After each set, three dashes are printed. The script checks for the existence of an argument, and if missing, prints an error. Passing the argument into the&nbsp;<i>sed</i>&nbsp;script is done by turning off the single quote mechanism, inserting the &quot;$1&quot; into the script, and starting up the single quote again:</p>
<p>
&nbsp;</p>
<pre>
#!/bin/sh
# grep3 - prints out three lines around pattern
# if there is only one argument, exit

case $# in
	1);;
	*) echo &quot;Usage: $0 pattern&quot;;exit;;
esac;
# I hope the argument doesn't contain a /
# if it does, sed will complain

# use sed -n to disable printing
# unless we ask for it
sed -n '
'/$1/' !{
	#no match - put the current line in the hold buffer
	x
	# delete the old one, which is
	# now in the pattern buffer
	d
}
'/$1/' {
	# a match - get last line
	x
	# print it
	p
	# get the original line back
	x
	# print it
	p
	# get the next line
	n
	# print it
	p
	# now add three dashes as a marker
	a\
---
	# now put this line into the hold buffer
	x
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/grep3.sh">grep3.sh</a></p>
<p>You could use this to show the three lines around a keyword, i.e.:</p>
<dl>
<dd>grep3 vt100 &lt;/etc/termcap
</dd>
</dl>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-55" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-55">Hold with h or H</a></h1>
<p>The &quot;x&quot; command exchanges the hold buffer and the pattern buffer. Both are changed. The &quot;h&quot; command copies the pattern buffer into the hold buffer. The pattern buffer is unchanged. An identical script to the above uses the hold commands:</p>
<p>
&nbsp;</p>
<pre>
#!/bin/sh
# grep3 version b - another version using the hold commands
# if there is only one argument, exit

case $# in
	1);;
	*) echo &quot;Usage: $0 pattern&quot;;exit;;
esac;

# again - I hope the argument doesn't contain a /

# use sed -n to disable printing 

sed -n '
'/$1/' !{
	# put the non-matching line in the hold buffer
	h
}
'/$1/' {
	# found a line that matches
	# append it to the hold buffer
	H
	# the hold buffer contains 2 lines
	# get the next line
	n
	# and add it to the hold buffer
	H
	# now print it back to the pattern space
	x
	# and print it.
	p
	# add the three hyphens as a marker
	a\
---
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/grep3a.sh">grep3a.sh</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-56" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-56">Keeping more than one line in the hold buffer</a></h1>
<p>The &quot;H&quot; command allows you to combine several lines in the hold buffer. It acts like the &quot;N&quot; command as lines are appended to the buffer, with a &quot;\n&quot; between the lines. You can save several lines in the hold buffer, and print them only if a particular pattern is found later.</p>
<p>As an example, take a file that uses spaces as the first character of a line as a continuation character. The files&nbsp;<i>/etc/termcap</i>,&nbsp;<i>/etc/printcap</i>,&nbsp;<i>makefile</i>&nbsp;and mail messages use spaces or tabs to indicate a continuing of an entry. If you wanted to print the entry before a word, you could use this script. I use a &quot;^I&quot; to indicate an actual tab character:</p>
<p>
&nbsp;</p>
<pre>
#!/bin/sh
# print previous entry
sed -n '
/^[ ^I]/!{
	# line does not start with a space or tab,
	# does it have the pattern we are interested in?
	'/$1/' {
		# yes it does. print three dashes
		i\
---
		# get hold buffer, save current line
		x
		# now print what was in the hold buffer
		p
		# get the original line back
		x
	}
	# store it in the hold buffer
	h
}
# what about lines that start
# with a space or tab?
/^[ ^I]/ {
	# append it to the hold buffer
	H
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/grep_previous.sh">grep_previous.sh</a></p>
<p>You can also use the &quot;H&quot; to extend the context grep. In this example, the program prints out the two lines before the pattern, instead of a single line. The method to limit this to two lines is to use the &quot;s&quot; command to keep one new line, and deleting extra lines. I call it&nbsp;<i>grep4</i>:</p>
<p>
&nbsp;</p>
<pre>
#!/bin/sh

# grep4: prints out 4 lines around pattern
# if there is only one argument, exit

case $# in
	1);;
	*) echo &quot;Usage: $0 pattern&quot;;exit;;
esac;

sed -n '
'/$1/' !{
	# does not match - add this line to the hold space
	H
	# bring it back into the pattern space
	x
	# Two lines would look like .*\n.*
	# Three lines look like .*\n.*\n.*
	# Delete extra lines - keep two
	s/^.*\n\(.*\n.*\)$/\1/
	# now put the two lines (at most) into
	# the hold buffer again
	x
}
'/$1/' {
	# matches - append the current line
	H
	# get the next line
	n
	# append that one also
	H
	# bring it back, but keep the current line in
	# the hold buffer. This is the line after the pattern,
	# and we want to place it in hold in case the next line
	# has the desired pattern
	x
	# print the 4 lines
	p
	# add the mark
	a\
---
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/grep4.sh">grep4.sh</a><br />
You can modify this to print any number of lines around a pattern. As you can see, you must remember what is in the hold space, and what is in the pattern space. There are other ways to write the same routine.</p>
<p>&nbsp;</p>
<h1><a name="uh-57" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-57">Get with g or G</a></h1>
<p>Instead of exchanging the hold space with the pattern space, you can copy the hold space to the pattern space with the &quot;g&quot; command. This deletes the pattern space. If you want to append to the pattern space, use the &quot;G&quot; command. This adds a new line to the pattern space, and copies the hold space after the new line.</p>
<p>Here is another version of the &quot;grep3&quot; command. It works just like the previous one, but is implemented differently. This illustrates that&nbsp;<i>sed</i>&nbsp;has more than one way to solve many problems. What is important is you understand your problem, and document your solution:</p>
<p>
&nbsp;</p>
<pre>
#!/bin/sh
# grep3 version c: use 'G'  instead of H

# if there is only one argument, exit

case $# in
	1);;
	*) echo &quot;Usage: $0 pattern&quot;;exit;;
esac;

# again - I hope the argument doesn't contain a /

sed -n '
'/$1/' !{
	# put the non-matching line in the hold buffer
	h
}
'/$1/' {
	# found a line that matches
	# add the next line to the pattern space
	N
	# exchange the previous line with the
	# 2 in pattern space
	x
	# now add the two lines back
	G
	# and print it.
	p
	# add the three hyphens as a marker
	a\
---
	# remove first 2 lines
	s/.*\n.*\n\(.*\)$/\1/
	# and place in the hold buffer for next time
	h
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/grep3c.sh">grep3c.sh</a></p>
<p>&nbsp;</p>
<p>The &quot;G&quot; command makes it easy to have two copies of a line. Suppose you wanted to the convert the first hexadecimal number to uppercase, and don&#8217;t want to use the script I described in an earlier column&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
# change the first hex number to upper case format
# uses sed twice
# used as a filter
# convert2uc &lt;in &gt;out
sed '
s/ /\
/' | \
sed ' {
	y/abcdef/ABCDEF/
	N
	s/\n/ /
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/convert2uc.sh">convert2uc.sh</a></p>
<p>&nbsp;</p>
<p>Here is a solution that does not require two invocations of&nbsp;<i>sed:</i>&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
# convert2uc version b
# change the first hex number to upper case format
# uses sed once
# used as a filter
# convert2uc &lt;in &gt;out
sed '
{
	# remember the line
	h
	#change the current line to upper case
	y/abcdef/ABCDEF/
	# add the old line back
	G
	# Keep the first word of the first line,
	# and second word of the second line
	# with one humongeous regular expression
	s/^\([^ ]*\) .*\n[^ ]* \(.*\)/\1 \2/
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/convert2uc1.sh">convert2uc1.sh</a><br />
Carl Henrik Lunde suggested a way to make this simpler. I was working too hard.&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
# convert2uc version b
# change the first hex number to upper case format
# uses sed once
# used as a filter
# convert2uc &lt;in &gt;out
sed '
{
	# remember the line
	h
	#change the current line to upper case
	y/abcdef/ABCDEF/
	# add the old line back
	G
	# Keep the first word of the first line,
	# and second word of the second line
	# with one humongeous regular expression
	s/ .* / / # delete all but the first and last word
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/convert2uc2.sh">convert2uc2.sh</a><br />
This example only converts the letters &quot;a&quot; through &quot;f&quot; to upper case. This was chosen to make the script easier to print in these narrow columns. You can easily modify the script to convert all letters to uppercase, or to change the first letter, second word, etc.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-58" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-58">Flow Control</a></h1>
<p>As you learn about&nbsp;<i>sed</i>&nbsp;you realize that it has it&#8217;s own programming language. It is true that it&#8217;s a very specialized and simple language. What language would be complete without a method of changing the flow control? There are three commands&nbsp;<i>sed</i>&nbsp;uses for this. You can specify a label with an text string preceded by a colon. The &quot;b&quot; command branches to the label. The label follows the command. If no label is there, branch to the end of the script. The &quot;t&quot; command is used to test conditions. Before I discuss the &quot;t&quot; command, I will show you an example using the &quot;b&quot; command.</p>
<p>&nbsp;</p>
<p>This example remembers paragraphs, and if it contains the pattern (specified by an argument), the script prints out the entire paragraph.&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed -n '
# if an empty line, check the paragraph
/^$/ b para
# else add it to the hold buffer
H
# at end of file, check paragraph
$ b para
# now branch to end of script
b
# this is where a paragraph is checked for the pattern
:para
# return the entire paragraph
# into the pattern space
x
# look for the pattern, if there - print
/'$1'/ p
'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/grep_paragraph.sh">grep_paragraph.sh</a></p>
<p>&nbsp;</p>
<h1><a name="uh-59" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-59">Testing with t</a></h1>
<p>You can execute a branch if a pattern is found. You may want to execute a branch only if a substitution is made. The command &quot;t label&quot; will branch to the label if the last substitute command modified the pattern space.</p>
<p>One use for this is recursive patterns. Suppose you wanted to remove white space inside parenthesis. These parentheses might be nested. That is, you would want to delete a string that looked like &quot;( ( ( ())) ).&quot; The&nbsp;<i>sed</i>&nbsp;expressions</p>
<dl>
<dd>sed &#8216;s/([ ^I]*)/g&#8217;
</dd>
</dl>
<p>would only remove the innermost set. You would have to pipe the data through the script four times to remove each set or parenthesis. You could use the regular expression</p>
<dl>
<dd>sed &#8216;s/([ ^I()]*)/g&#8217;
</dd>
</dl>
<p>&nbsp;</p>
<p>but that would delete non-matching sets of parenthesis. The &quot;t&quot; command would solve this:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
:again
	s/([ ^I]*)//g
	t again
'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/delete_nested_parens.sh">delete_nested_parens.sh</a></p>
<p>&nbsp;</p>
<h1><a name="uh-60" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-60">An alternate way of adding comments</a></h1>
<p>There is one way to add comments in a&nbsp;<i>sed</i>&nbsp;script if you don&#8217;t have a version that supports it. Use the &quot;a&quot; command with the line number of zero:&nbsp;<br />
&nbsp;</p>
<pre>
#!/bin/sh
sed '
/begin/ {
0i\
	This is a comment\
	It can cover several lines\
	It will work with any version of sed
}'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_add_comments.sh">sed_add_comments.sh</a></p>
<p>&nbsp;</p>
<h1><a name="uh-61" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-61">The poorly undocumented ;</a></h1>
<p>There is one more&nbsp;<i>sed</i>&nbsp;command that isn&#8217;t well documented. It is the &quot;;&quot; command. This can be used to combined several&nbsp;<i>sed</i>&nbsp;commands on one line. Here is the&nbsp;<i>grep4</i>&nbsp;script I described earlier, but without the comments or error checking and with semicolons between commands:&nbsp;</p>
<p>#!/bin/sh<br />
sed -n &#8216;<br />
&#8216;/$1/&#8217; !{;H;x;s/^.*\n\(.*\n.*\)$/\1/;x;}<br />
&#8216;/$1/&#8217; {;H;n;H;x;p;a\<br />
&#8212;<br />
}&#8217;</p>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/grep4a.sh">grep4a.sh</a></p>
<p>Yessireebob! Definitely character building. I think I have made my point. As far as I am concerned, the only time the semicolon is useful is when you want to type the&nbsp;<i>sed</i>&nbsp;script on the command line. If you are going to place it in a script, format it so it is readable. I have mentioned earlier that many versions of&nbsp;<i>sed</i>&nbsp;do not support comments except on the first line. You may want to write your scripts with comments in them, and install them in &quot;binary&quot; form without comments. This should not be difficult. After all, you have become a&nbsp;<i>sed</i>&nbsp;guru by now. I won&#8217;t even tell you how to write a script to strip out comments. That would be insulting your intelligence.</p>
<p>&nbsp;</p>
<h1><a name="uh-62" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-62">Passing regular expressions as arguments</a></h1>
<p>In the earlier scripts, I mentioned that you would have problems if you passed an argument to the script that had a slash in it. In fact, regular expression might cause you problems. A script like the following is asking to be broken some day:</p>
<pre>
#!/bin/sh
sed 's/'&quot;$1&quot;'//g'
</pre>
<p>If the argument contains any of these characters in it, you may get a broken script: &quot;/\.*[]^$&quot; For instance, if someone types a &quot;/&quot; then the substiture command will see four delimiters instead of three. You will also get syntax errors if you provide a &quot;]&quot; without a &quot;]&quot;. One solution is to have the user put a backslash before any of these characters when they pass it as an argument. However, the user has to know which characters are special.&nbsp;<br />
Another solution is to add a backslash before each of those characters in the script</p>
<pre>
#!/bin/sh
arg=`echo &quot;$1&quot; | sed 's:[]\[\^\$\.\*\/]:\\\\&amp;:g'`
sed 's/'&quot;$arg&quot;'//g'
</pre>
<p>
Click here to get file:&nbsp;<a href="http://www.grymoire.com/Unix/Scripts/sed_with_regular_expressions1.sh">sed_with_regular_expressions1.sh</a><br />
If you were searching for the pattern &quot;^../,&quot; the script would convert this into &quot;\^\.\.\/&quot; before passing it to&nbsp;<i>sed</i>.</p>
<p>&nbsp;</p>
<h1><a name="uh-63" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-63">Command Summary</a></h1>
<p>As I promised earlier, here is a table that summarizes the different commands. The second column specifies if the command can have a range or pair of addresses (with a 2) or a single address or pattern (with a 1). The next four columns specifies which of the four buffers or streams are modified by the command. Some commands only affect the output stream, others only affect the hold buffer. If you remember that the pattern space is output (unless a &quot;-n&quot; was given to&nbsp;<i>sed</i>), this table should help you keep track of the various commands.</p>
<pre>
+--------------------------------------------------------+
 |Command   Address		Modifications to	  |
 |	    or Range   Input	Output	 Pattern   Hold	  |
 |		       Stream	Stream	 Space	   Buffer |
 +--------------------------------------------------------+
 |=	    -	       -	Y	 -	   -	  |
 |a	    1	       -	Y	 -	   -	  |
 |b	    2	       -	-	 -	   -	  |
 |c	    2	       -	Y	 -	   -	  |
 |d	    2	       Y	-	 Y	   -	  |
 |D	    2	       Y	-	 Y	   -	  |
 |g	    2	       -	-	 Y	   -	  |
 |G	    2	       -	-	 Y	   -	  |
 |h	    2	       -	-	 -	   Y	  |
 |H	    2	       -	-	 -	   Y	  |
 |i	    1	       -	Y	 -	   -	  |
 |l	    1	       -	Y	 -	   -	  |
 |n	    2	       Y	*	 -	   -	  |
 |N	    2	       Y	-	 Y	   -	  |
 |p	    2	       -	Y	 -	   -	  |
 |P	    2	       -	Y	 -	   -	  |
 |q	    1	       -	-	 -	   -	  |
 |r	    1	       -	Y	 -	   -	  |
 |s	    2	       -	-	 Y	   -	  |
 |t	    2	       -	-	 -	   -	  |
 |w	    2	       -	Y	 -	   -	  |
 |x	    2	       -	-	 Y	   Y	  |
 |y	    2	       -	-	 Y	   -	  |
 +--------------------------------------------------------+</pre>
<p>The &quot;n&quot; command may or may not generate output, depending on the &quot;-n&quot; option. The &quot;r&quot; command can only have one address, despite the documentation.</p>
<p>&nbsp;</p>
<h1><a name="uh-64" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-64">In Conclusion</a></h1>
<p>This concludes my tutorial on&nbsp;<i>sed</i>. It is possible to find shorter forms of some of my scripts. However, I chose these examples to illustrate some basic constructs. I wanted clarity, not obscurity. I hope you enjoyed it.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1><a name="uh-65" href="http://www.grymoire.com/Unix/Sed.html#toc-uh-65">More References</a></h1>
<p>This concludes my tutorial on Other of my Unix shell tutorials can be found&nbsp;<a href="http://www.grymoire.com/Unix">here.</a>&nbsp;Other shell tutorials can be found at&nbsp;<a href="http://www.shelldorado.com/links/index.html#tutorials">Heiner&#8217;s SHELLdorado</a>&nbsp;and&nbsp;<a href="http://cfaj.freeshell.org/shell/">Chris F. A. Johnson&#8217;s Unix Shell Page</a><br />
<a href="http://en.wikipedia.org/wiki/Sed">The Wikipedia Entry on SED</a><br />
<a href="http://student.northpark.edu/pemente/sed/sed1line.txt">SED one-liners</a></p>
<p>And don&#8217;t forget&nbsp;<a href="http://sed.sourceforge.net/sedfaq.html">The SED FAQ</a>&nbsp;</p>
<p>This document was originally converted from NROFF to TEXT to HTML.&nbsp;<br />
please forgive errors in the translation.&nbsp;<br />
If you are confused, grab the actual script if possible. No translations occured in the scripts.&nbsp;</p>
<p>Thanks to Carl Henrik Lunde who suggested an improvement to convert2uc1.sh&nbsp;<i>This document was translated by troff2html v0.21 on September 22, 2001 and then manually edited to make it compliant with:</i>&nbsp;<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88" /></a></p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://smultron.es/2009/09/parseo-en-bash-linux-shell-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

