<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>grep &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/grep/</link>
	<description>Feed of posts on WordPress.com tagged "grep"</description>
	<pubDate>Sun, 29 Nov 2009 13:46:58 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[grepping a range of lines using perl.]]></title>
<link>http://peeterjoot.wordpress.com/2009/11/27/grepping-a-range-of-lines-using-perl/</link>
<pubDate>Fri, 27 Nov 2009 15:29:04 +0000</pubDate>
<dc:creator>peeterjoot</dc:creator>
<guid>http://peeterjoot.wordpress.com/2009/11/27/grepping-a-range-of-lines-using-perl/</guid>
<description><![CDATA[I was asked how to use grep to select everything in a file starting with a pattern, and ending with ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I was asked how to use grep to select everything in a file starting with a pattern, and ending with a different one.  The file is our diagnostic log and if this has originated with one of our system testers could be massive (a few hundred thousand lines long).  gnu-grep can be used for this.  You could do something like:</p>
<pre>grep -A 9999999 'some first expression' &#60; wayToBigFile &#124; grep -B 9999999 'some other expression'
</pre>
<p>Here 9999999 is some number of lines that is guessed big enough to contain all the lines of interest (not known ahead of time), so the command says &#8220;give me everything after the expression, and then give me everything before the other expression in that output&#8221;</p>
<p>Perl gives you a nicer way of doing this:</p>
<pre>#!/usr/bin/perl -n

$foundIt = 1 if ( /some first expression/ ) ;

next if ( !$foundIt ) ;

print ;

exit if ( /some other expression/ ) ;

# done.
</pre>
<p>The -n flag says to run the whole script as if it is in a &#8216;while (&#60;&#62;){ &#8230; }&#8217; loop.  Until the initial pattern is seen $foundIt is false, and nothing will be printed, and we bail if the second pattern is seen.  Note that this relies on perl&#8217;s lazy variable initialization, since $foundIt = 0 until modified.</p>
<p>Observe also that this script is actually also it&#8217;s own test case.</p>
<pre>
myPrompt$ chmod 755 ./theScript
myPrompt$ ./theScript &#60; ./theScript
$foundIt = 1 if ( /some first expression/ ) ;

next if ( !$foundIt ) ;

print ;

exit if ( /some other expression/ ) ;
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[File grepping utility]]></title>
<link>http://soulfulsyntax.wordpress.com/2009/11/25/file-grepping-utility/</link>
<pubDate>Wed, 25 Nov 2009 15:51:47 +0000</pubDate>
<dc:creator>ChocolateSoul</dc:creator>
<guid>http://soulfulsyntax.wordpress.com/2009/11/25/file-grepping-utility/</guid>
<description><![CDATA[I wrote a utility that can grep through flat files and look for user-defined regular expressions. I ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I wrote a utility that can grep through flat files and look for user-defined regular expressions. I included the ability to search the files and adjacent folders recursively, as well as the capability to count the number of lines (per file) that results were found on. There are a few more configurable options to control the search (disable/enable cases sensitivity or search file names). Lines that contain the regular expression are returned right to the results window!</p>
<p>Screenshot (click the image to enlarge it):</p>
<p><a href="http://soulfulsyntax.wordpress.com/files/2009/11/rubberneck.png"><img class="alignnone size-medium wp-image-63" title="Rubberneck" src="http://soulfulsyntax.wordpress.com/files/2009/11/rubberneck.png?w=300" alt="" width="300" height="137" /></a></p>
<p>Download Link:</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[Unix based] Busca e leitura dos arquivos]]></title>
<link>http://srpantano.wordpress.com/2009/11/21/busca-e-leitura-dos-arquivos/</link>
<pubDate>Sat, 21 Nov 2009 16:37:12 +0000</pubDate>
<dc:creator>srpantano</dc:creator>
<guid>http://srpantano.wordpress.com/2009/11/21/busca-e-leitura-dos-arquivos/</guid>
<description><![CDATA[Como utilizo muito terminal  Solaris no trabalho e Ubuntu em casa, um pequeno script é muito útil qu]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Como utilizo muito terminal  Solaris no trabalho e Ubuntu em casa, um pequeno script é muito útil quando fazemos uma busca por arquivos e no resultado queremos saber qual deles tem um determinado texto dentro:</p>
<p><code>$ for i in `find . -name '*.trc' -ls &#124; grep 'Apr 22' &#124; awk -F" " '{ print $9 }'`; do grep "texto" $i; done</code></p>
<p>excplicando:</p>
<p><strong>for i in</strong> # loop com a iteração em i<strong></strong></p>
<p style="padding-left:30px;"><strong>`find . -name &#8216;*.trc&#8217; -exec -ls -l {}; &#124; grep &#8216;Apr 22&#8242; &#124; aw&#8217;k -F&#8221; &#8221; &#8216;{ print  $8}&#8217;`;</strong><em> </em> # primeiro procure, a partir do diretório atual todos arquivos com extensão .trc e os mostre utilizando um &#8220;ls -l&#8221;, na lista filtre os arquivos pela data de 22 de abril e por fim exiba somente a 8 coluna da lista, usando espaço como separador de colunas.</p>
<p style="padding-left:30px;"><strong>do grep &#8220;texto&#8221; $i;</strong> # a partir do resultado da linha acima faz uma busca do texto em cada arquivo<strong></strong></p>
<p><strong>done</strong> # final do for</p>
<p>Um observação importante é que a data e a quantidade de colunas pode variar de acordo com o sistema operacional.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Recursive Grep Example]]></title>
<link>http://jaysonlorenzen.wordpress.com/2009/11/20/recursive-grep-example/</link>
<pubDate>Fri, 20 Nov 2009 21:57:28 +0000</pubDate>
<dc:creator>Jayson</dc:creator>
<guid>http://jaysonlorenzen.wordpress.com/2009/11/20/recursive-grep-example/</guid>
<description><![CDATA[Nothing really needing explaining here, but wanted an example for doing a recrsive grep handy as I c]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Nothing really needing explaining here, but wanted an example for doing a recrsive grep handy as I can never remember it.</p>
<p>&#160;</p>
<p>grep -RH &#8211;include &#8220;*.java&#8221; TEXT_I_AM_LOOKING_FOR *</p>
<p>&#160;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Comandos Infaltables!!]]></title>
<link>http://freeakx.wordpress.com/2009/11/18/comandos-infaltables/</link>
<pubDate>Wed, 18 Nov 2009 21:40:20 +0000</pubDate>
<dc:creator>Cesar Troya S.</dc:creator>
<guid>http://freeakx.wordpress.com/2009/11/18/comandos-infaltables/</guid>
<description><![CDATA[En esta Oportunidad les Traigo una recopilación de lo q yo concidero son los comandos más, utiles, i]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>En esta Oportunidad les Traigo una recopilación de lo q yo concidero son los comandos más, utiles, importantes y usados tanto en Ubuntu como en muchas otras distros linux</p>
<ul>
<li style="text-align:left;"><strong>Adduser: </strong>Se utiliza para añadir un usuario.</li>
</ul>
<blockquote>
<blockquote><p>Uso: adduser &#60;nombreusuario&#62;</p></blockquote>
</blockquote>
<ul>
<li><strong>Alias (este esta bien explicado en un post anterior)<br />
</strong></li>
</ul>
<p style="padding-left:120px;">Uso: alias nombrequeledamos=’comando’</p>
<ul>
<li><strong>apt-get install nombredelprograma</strong><strong> =  i</strong>nstala el paquete.</li>
</ul>
<ul>
<li><strong>apt-get remove nombredelprograma = </strong>Borra el paquete. Con la opción –purge borra tambien la configuración del paquete instalado.</li>
</ul>
<ul>
<li><strong>apt-get update = </strong>Actualiza la lista de paquetes disponibles para instalar.</li>
</ul>
<ul>
<li style="text-align:left;"><strong>apt-get upgrade  = </strong>Instala las nuevas versiones de los diferentes paquetes disponibles.</li>
</ul>
<ul>
<li><strong>cd = </strong>Cambia el directorio.</li>
</ul>
<blockquote><p>Uso: cd nombredirectorio</p></blockquote>
<p><span style="color:#ff6600;"><em><strong>Continuar leyendo el resto de comandos:</strong></em></span></p>
<ul>
<li><!--more--><strong>chmod: </strong>Cambia los permisos de los archivos.</li>
</ul>
<p style="padding-left:90px;">r:lectura w:escritura x:ejecución<br />
+: añade permisos -:quita permisos<br />
u:usuario g:grupo del usuario o:otros<br />
Uso: chmod permisos nombrearchivo</p>
<ul>
<li><strong>chown: </strong>Cambia el propietario de un archivo.</li>
</ul>
<p style="padding-left:90px;">Uso: chown &#60;nombrepropietario&#62; &#60;nombrearchivo&#62;</p>
<ul>
<li><strong>cp:</strong>Copia archivos en el directorio indicado.</li>
</ul>
<p style="padding-left:60px;">Uso: cp archivoorigen archivodestino</p>
<ul>
<li><strong>deluser: </strong>Elimina una cuenta de usuario</li>
</ul>
<p style="padding-left:90px;">Uso: deluser &#60;nombreusuario&#62;</p>
<ul>
<li><strong>exit:</strong> Cierra las ventanas o las conexiones remotas establecidas</li>
</ul>
<ul>
<li><strong>fsck: </strong>Sirve para chequear si hay errores en nuestro disco duro.</li>
</ul>
<p style="padding-left:90px;">Uso: fsck -t &#60;fs_typo&#62; &#60;dispositivo&#62;</p>
<ul>
<li><strong>ftp: </strong>Protocolo de Transferencia de Archivos, permite transferir archivos de y para computadores remotos.</li>
</ul>
<p style="padding-left:60px;">Uso: ftp &#60;maquina_remota&#62;</p>
<ul>
<li><strong>grep</strong>: Su funcionalidad es la de escribir en salida estándar aquellas líneas que concuerden con un patrón. Busca patrones en archivos.</li>
</ul>
<p style="padding-left:90px;">grep: grep &#60;patronabuscar&#62; &#60;nombrearchivos&#62;</p>
<ul>
<li><strong>ifconfig: </strong>Obtener información de la configuración de red</li>
</ul>
<ul>
<li><strong>kill:</strong> Termina un proceso</li>
</ul>
<p style="padding-left:60px;">Uso: kill numeroPID</p>
<ul>
<li><strong>ls:</strong>Lista los archivos y directorios dentro del directorio de trabajo.</li>
</ul>
<ul>
<li><strong>make:</strong> Crea ejecutables a partir de los archivos fuente.</li>
</ul>
<ul>
<li><strong>man: </strong>muestra el manual de un programa o comando si este esta disponible</li>
</ul>
<p style="padding-left:90px;">Uso: man &#60;nombredelcomando&#62;</p>
<ul>
<li><strong>mkdir: </strong>Crea un nuevo directorio.</li>
</ul>
<p style="padding-left:90px;">Uso: mkdir nombredirectorio</p>
<ul>
<li><strong>mount: </strong>Monta una unidad.</li>
</ul>
<p style="padding-left:90px;">Uso: mount -t&#60; sistema_de_archivo&#62; &#60;dispositivo&#62; &#60;nombredirectorio&#62;</p>
<p><strong><br />
</strong></p>
<ul>
<li><strong>mv: </strong>Este comando sirve para renombrar un archivo.</li>
</ul>
<p style="padding-left:60px;">Uso: mv &#60;nombrearchivo&#62; &#60;nuevonombrearchivo&#62;</p>
<ul>
<li><strong>netstat:</strong>Muestra las conexiones y puertos abiertos por los que se establecen las comunicaciones.</li>
</ul>
<ul>
<li><strong>poweroff: </strong>Apaga el ordenador.</li>
</ul>
<ul>
<li><strong>ps: </strong>Muestra información acerca de los procesos activos.</li>
</ul>
<ul>
<li><strong>rlogin: </strong>Conecta un host local con un host remoto.</li>
</ul>
<p style="padding-left:90px;">Uso: rlogin &#60;maquina_remota&#62;</p>
<ul>
<li><strong>rm: </strong>Remueve o elimina un archivo.</li>
</ul>
<p style="padding-left:60px;">Uso: rm &#60;rutaynombrearchivo&#62;</p>
<ul>
<li><strong>rmdir: </strong>Elimina el directorio indicado, el cual debe estar vacío.</li>
</ul>
<p style="padding-left:90px;">Uso: rmdir nombredirectorio</p>
<ul>
<li><strong>sudo o su:</strong> Con este comando accedemos al sistema como root.</li>
</ul>
<ul>
<li><strong>umount: </strong>Desmontar unidades montadas anteriormente</li>
</ul>
<p style="padding-left:120px;">Uso: umount &#60;nombredirectorio&#62;</p>
<ul>
<li><strong>wc:</strong>Cuenta los caráteres, palabras y líneas del archivo de texto.</li>
</ul>
<p style="padding-left:60px;">Uso: wc nom_archivo</p>
<p style="padding-left:60px;">
<ul>
<li><strong>whereis: </strong>Devuelve la ubicación del archivo especificado, si existe.</li>
</ul>
<p style="padding-left:60px;">Uso: whereis nomb_archivo</p>
<p><strong>Larga vida a la consola!!</strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[A Small Bit of Enlightenment]]></title>
<link>http://whereofwecannotspeak.wordpress.com/2009/11/17/a-small-bit-of-enlightenment/</link>
<pubDate>Tue, 17 Nov 2009 16:54:41 +0000</pubDate>
<dc:creator>whereofwecannotspeak</dc:creator>
<guid>http://whereofwecannotspeak.wordpress.com/2009/11/17/a-small-bit-of-enlightenment/</guid>
<description><![CDATA[Someone once asked me in an interview: &#8220;What is your favorite Unix tool?&#8221; Not sure of wh]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>
Someone once asked me in an interview:  &#8220;What is your favorite Unix tool?&#8221;  Not sure of what to say, I simply tried to avoid appearing ignorant, and replied:  &#8220;grep.&#8221;</p>
<p>
Thinking about this problem again, I realized that there is a much better answer.  Today, my favorite Unix tool is: <em>the pipe</em>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Truco del día: Excluir al proceso grep en la salida de ps aux]]></title>
<link>http://flossblog.wordpress.com/2009/11/11/truco-del-dia-excluir-al-proceso-grep-en-la-salida-de-ps-aux/</link>
<pubDate>Wed, 11 Nov 2009 20:32:23 +0000</pubDate>
<dc:creator>sedlav</dc:creator>
<guid>http://flossblog.wordpress.com/2009/11/11/truco-del-dia-excluir-al-proceso-grep-en-la-salida-de-ps-aux/</guid>
<description><![CDATA[Con regularidad uso ps ax | grep patron para obtener información sobre un proceso determinado, pero ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div style="line-height:172%;font-size:11px;">
<p>Con regularidad uso <b>ps ax &#124; grep patron</b> para obtener información sobre un proceso determinado, pero en la salida también se incluye el proceso grep ¿Cómo evitar esto?</p>
<p>Simplemente encierra entre corchetes la primera letra o número del patrón, por ejemplo:</p>
<h5>Si</h5>
<p><code style="background-image:none;padding-left:5px;font-family:monospace;">$ ps ax &#124; grep firefox</code></p>
<p>muestra</p>
<pre>
28089 ?        S      0:00 /bin/sh /usr/lib/firefox-3.0.8/run-mozilla.sh /usr/lib/firefox-3.0.8/firefox
28103 ?        Sl    26:25 /usr/lib/firefox-3.0.8/firefox
28785 pts/5    S+     0:00 grep firefox
</pre>
<h5>Entonces</h5>
<p><code style="background-image:none;padding-left:5px;font-family:monospace;">ps ax &#124; grep [f]irefox</code></p>
<p>mostraría</p>
<pre>
28089 ?        S      0:00 /bin/sh /usr/lib/firefox-3.0.8/run-mozilla.sh /usr/lib/firefox-3.0.8/firefox
28103 ?        Sl    26:27 /usr/lib/firefox-3.0.8/firefox
</pre>
<h5>Tambien puedes usar</h5>
<p><code style="background-image:none;padding-left:5px;font-family:monospace;">ps ax &#124; grep patron &#124; grep -v patron</code></p>
<h3>Lecturas recomendadas</h3>
<ul style="list-style:none;margin:0;padding:0;">
<li>- man ps</li>
<li>- info grep</li>
<li>- <a href="http://flossblog.wordpress.com/2009/10/27/buscar-palabras-claves-en-uno-o-varios-ficheros/">Buscar palabras claves en uno o varios ficheros</a></li>
</ul>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[grep utilities: hgrep (highlighted grep) and rgrep (recursive grep)]]></title>
<link>http://h446log.wordpress.com/2009/11/09/grep-utilities-hgrep-highlighted-grep-and-rgrep-recursive-grep/</link>
<pubDate>Mon, 09 Nov 2009 21:17:56 +0000</pubDate>
<dc:creator>h446log</dc:creator>
<guid>http://h446log.wordpress.com/2009/11/09/grep-utilities-hgrep-highlighted-grep-and-rgrep-recursive-grep/</guid>
<description><![CDATA[1. hgrep displays grep results in highlights. 2. rgrep runs grep on all the files in a directory tre]]></description>
<content:encoded><![CDATA[1. hgrep displays grep results in highlights. 2. rgrep runs grep on all the files in a directory tre]]></content:encoded>
</item>
<item>
<title><![CDATA[modules.pcimap file missing for the 2.6.26-2-686 kernel version]]></title>
<link>http://linuxindetails.wordpress.com/2009/11/07/modules-pcimap-file-missing-for-the-2-6-26-2-686-kernel-version/</link>
<pubDate>Sat, 07 Nov 2009 13:52:40 +0000</pubDate>
<dc:creator>linuxindetails</dc:creator>
<guid>http://linuxindetails.wordpress.com/2009/11/07/modules-pcimap-file-missing-for-the-2-6-26-2-686-kernel-version/</guid>
<description><![CDATA[modules.pcimap file can be found in the following directory : /lib/modules/$(uname -r)/ This file is]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><pre class="message">modules.pcimap file can be found in the following directory :
<strong>/lib/modules/$(uname -r)/</strong>

This file is used to find the corresponding module for a PCI device
providing the model id through a <strong>'grep' </strong>command :
Here, the model id is 0900 :

<strong>grep 0900 /lib/modules/2.6.26-2-686/modules.pcimap &#124;more
</strong>
The result consists of many matching lines. Only one is the good one.
You have to issue a new <strong>'grep'</strong> command with the vendor id :
Here, the vendor id is 1039 :

<strong>grep 0900 /lib/modules/2.6.26-2-686/modules.pcimap &#124;grep 1039</strong>

And the result is : 

<strong> sis900            0x00001039 0x00000900  0xffffffff 0xffffffff 0x00000000 0x00000000    0x0</strong>

If you want to have more infos about this module : 

<strong>modinfo sis900</strong>

To create or to re-create this modules.pcimap file, issue the command below :

<strong>depmod -a -m -F /boot/System.map-2.6.26-2-686 2.6.26-2-686</strong>
</pre>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=1cff0146-3f5f-897f-a38d-69dd5fc1b233" alt="" /></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Searching Source Code: LXR and grep]]></title>
<link>http://saherneklawy.wordpress.com/2009/11/02/searching-source-code-lxr-and-grep/</link>
<pubDate>Sun, 01 Nov 2009 23:07:02 +0000</pubDate>
<dc:creator>saherneklawy</dc:creator>
<guid>http://saherneklawy.wordpress.com/2009/11/02/searching-source-code-lxr-and-grep/</guid>
<description><![CDATA[Looking for a certain functionality in someone else&#8217;s code could prove to be a tough challenge]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Looking for a certain functionality in someone else&#8217;s code could prove to be a tough challenge. This is increased by the size of the given project. Many systems exist today facilitating easy search in a project. For Java, eclipse is best used for that task, as it contains a strong in java class indexing, classification, and searching.</p>
<p>Some projects provide for you a portal to search their code base. Famous examples of these are <a href="http://lxr.linux.no/">LXR</a> for the Linux kernel, and it&#8217;s customized version <a href="http://mxr.mozilla.org/">MXR</a> used for Mozilla projects.</p>
<p>When all the above options are not available, the alternative exists natively in most linux systems. This is namely &#8220;grep&#8221;. <a href="http://en.wikipedia.org/wiki/Grep">Grep</a> is a strong command for regular expression matching. On if it&#8217;s features is that it can also match to the content within files. Putting that in mind, the following command could be very useful:</p>
<p><code> grep -R "search query" . </code></p>
<p>This looks recursively for all mentions of <code>search query</code> in all files under the current directory. This prints output in the console the file name where this query was found, and the line that included it.</p>
<p>To be able to store this search result in a file, the output could be piped as follows:</p>
<p><code> grep -R "search query" . &#62; log.txt </code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[osx] Eject a volume 'unwilling' to be ejected!]]></title>
<link>http://nixtricks.wordpress.com/2009/10/31/osx-eject-a-volume-unwilling-to-be-ejecte/</link>
<pubDate>Sat, 31 Oct 2009 18:16:58 +0000</pubDate>
<dc:creator>kousik</dc:creator>
<guid>http://nixtricks.wordpress.com/2009/10/31/osx-eject-a-volume-unwilling-to-be-ejecte/</guid>
<description><![CDATA[I sometime have problem finding which persistent process is not letting me eject a volume (CD/DVD/US]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I sometime have problem finding which persistent process is not letting  me eject a volume (CD/DVD/USB drive). The error message is not very helpful at all:</p>
<blockquote><p>Try quitting applications</p></blockquote>
<p>OK, but which one(s)? I often have hard time figuring that out using htop/ top or a combination of ps and grep.</p>
<p>But actually this is what I  want:</p>
<div style="border:1px dotted black;padding:1em;"><code>$ lsof &#124; grep -i Volume_Name</code></div>
<p>where Volume_Name is the name of the volume (or an &#8216;identifying&#8217; part of the name) I want to eject. This gives me the name(s) and process ID(s) of the run-away process(es) as well as the path to the file(s) in use on the volume, Volume_Name.</p>
<p>Now that I know the names I should first try to save the documents and quit the applications involved in the normal way. However, if a particular application does not oblige, I can always kill it (with the risk of potential data loss!) using its process ID (say, 123):</p>
<div style="border:1px dotted black;padding:1em;"><code>$ kill -9 123</code></div>
<p>After that, the ejection of the volume should not be difficult at all.</p>
<p>Needless to say, being a Unix utility, <code>lsof</code> (=&#8220;list open files&#8221;) may be used on other *nix-based systems as well.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Buscar palabras claves en uno o varios ficheros]]></title>
<link>http://flossblog.wordpress.com/2009/10/27/buscar-palabras-claves-en-uno-o-varios-ficheros/</link>
<pubDate>Tue, 27 Oct 2009 19:41:15 +0000</pubDate>
<dc:creator>sedlav</dc:creator>
<guid>http://flossblog.wordpress.com/2009/10/27/buscar-palabras-claves-en-uno-o-varios-ficheros/</guid>
<description><![CDATA[grep es un utilitario (basado en líneas de comandos) que permite relizar búsquedas de palabras y/o p]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div style="line-height:172%;font-size:11px;">
<p>
grep es un utilitario (basado en líneas de comandos) que permite relizar búsquedas de palabras y/o patrones en un fichero o grupo de ficheros. Su nombre es tomado de &#8220;<strong>g</strong>lobal <strong>r</strong>egular <strong>e</strong>xpression <strong>p</strong>rint&#8221;. Por defecto grep busca las líneas que coinciden y las imprime en<br />
la salida estándard</p>
<h3>Usos</h3>
<h5>Sintaxis general</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code><br />
$ grep [opciones] patrón [fichero] ó<br />
$ grep [opciones] -f fichero-que-contiene-los-patrones-de-búsqueda fichero<br />
</code></div>
<div style="background-color:graytext;width:570px;padding:20px;">
Opciones básicas:</p>
<ul style="list-style:none;margin:0;padding:0;">
<li style="margin:5px 0;"><strong>-c:</strong> Cuenta el número de coincidencias</li>
<li style="margin:5px 0;"><strong>-E:</strong> Expresión regular extendida</li>
<li style="margin:5px 0;"><strong>-f:</strong> Obtiene el patrón o los patrones de búsqueda de un fichero (Uno por cada línea)</li>
<li style="margin:5px 0;"><strong>-i:</strong> Insensible a mayúsculas y minúsculas</li>
<li style="margin:5px 0;"><strong>-l:</strong> Imprime el nombre de cada fichero de entrada donde se encuentren coincidencias</li>
<li style="margin:5px 0;"><strong>-n:</strong> Imprime el número de línea en donde se encuentren coincidencias</li>
<li style="margin:5px 0;"><strong>-o:</strong> Imprime sólo la parte que coincide</li>
<li style="margin:5px 0;"><strong>-v:</strong> Invierte el sentido de la búsqueda</li>
</ul>
<p>Extensiones <a href="http://www.gnu.org">GNU</a>:</p>
<ul style="list-style:none;margin:0;padding:0;">
<li style="margin:5px 0;"><strong>&#8211;color:</strong> Resalta la palabra que coincide con el color especificado en la variable de entorno GREP_COLOR, rojo por defecto</li>
<li style="margin:5px 0;"><strong>-r,-R:</strong> Busca coincidencias en todos los ficheros que se encuentran debajo de un directorio, incluyendo los subdirectorios</li>
</ul>
<p>Nota: No se abordan todas las opciones</p>
</div>
<p>A partir del fichero (frutas.txt), el cuál contiene las siguientes líneas:</p>
<p>La Manzana es una fruta pomácea comestible obtenida del manzano doméstico</p>
<p>La ManZana es una de las frutas más cultivadas del mundo</p>
<p>La manzana puede comerse fresca pelada o con piel</p>
<p>MANZANA Cameo</p>
<p>Mango</p>
<p>Mamey</p>
<p>Güayaba</p>
<p>Pera</p>
<p>Se elaboró los,</p>
<h3>Ejemplos</h3>
<h5>Sensible a mayúsculas y minúsculas</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code><br />
$ grep manzana frutas.txt</code>
<p>La manzana puede comerse fresca pelada o con piel</p>
</div>
<h5>Insensible a mayúsculas y minúsculas</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code><br />
$ grep -i manzana frutas.txt</code><br />La Manzana es una fruta pomácea comestible obtenida del manzano doméstico<br />
La ManZana es una de las frutas más cultivadas del mundo<br />
La manzana puede comerse fresca pelada o con piel<br />
MANZANA Cameo</p>
</div>
<h5>Contar el número de coincidencias</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -c manzana frutas.txt</code><br />1
</div>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -ci manzana frutas.txt</code><br />4
</div>
<h5>Prefijar número de línea</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -n manzana frutas.txt</code><br />3:La manzana puede comerse fresca pelada o con piel
</div>
<h5>Sólo la parte que coincide</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -o manzana frutas.txt</code><br />manzana
</div>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -io manzana frutas.txt</code><br />Manzana<br />
ManZana<br />
manzana <br />
MANZANA 
</div>
<h5>Encontrar las líneas que contienen manzana o Mamey</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -E 'manzana&#124;Mamey' frutas.txt</code><br />La manzana puede comerse fresca pelada o con piel<br />
Mamey
</div>
<h5>Invertir la búsqueda</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -v manzana frutas.txt</code><br />La Manzana es una fruta pomácea comestible obtenida del manzano doméstico<br />
La ManZana es una de las frutas más cultivadas del mundo<br />
MANZANA Cameo<br />
Mango<br />
Mamey<br />
Güayaba<br />
Pera
</div>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -iv manzana frutas.txt</code><br />Mango<br />
Mamey<br />
Güayaba<br />
Pera
</div>
<h5>Resaltar coincidencia</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep ana --color=always frutas.txt</code></div>
<p><img class="alignnone size-full wp-image-43" title="higtlight" src="http://flossblog.wordpress.com/files/2009/10/higtlight.jpg" alt="higtlight" width="512" height="45" /></p>
<p>El <a href="http://www.termsys.demon.co.uk/vtansi.htm#colors">color</a> de resaltado puede cambiarse estableciendo la variable de entorno GREP_COLOR, ejemplo export GREP_COLOR=&#8217;1;32&#8242;
</p>
<h5>Nombre de los ficheros donde se encuentren coincidencias, esta opción es muy útil cuando se combina con búquedas recursivas (-r,-R)</h5>
<div style="border:1px dashed #cccccc;background-color:#f4f5f7;margin:5px 0;padding:8px 12px 8px 10px;"><code class="cli"><br />
$ grep -lR estudiante projects/matricula/src</code></div>
<p>El ejemplo anterior encuentra todos los ficheros que contienen la palabra estudiante</p>
<h3>Lecturas recomendadas</h3>
<p><a>man grep ó info grep</a><br />
<a href="http://es.wikipedia.org/wiki/Grep">grep en wikipedia</a>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux - Localizar arquivo contendo texto especificado]]></title>
<link>http://andreysmith.wordpress.com/2009/10/24/localizar-texto-linux/</link>
<pubDate>Sat, 24 Oct 2009 21:29:31 +0000</pubDate>
<dc:creator>Andrey Smith</dc:creator>
<guid>http://andreysmith.wordpress.com/2009/10/24/localizar-texto-linux/</guid>
<description><![CDATA[Introdução Certa vez, após instalar o GLPI (sistema de helpdesk), houve a necessidade de customiza-l]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img src="http://andreysmith.wordpress.com/files/2009/10/lupa1.jpg?w=128" alt="lupa" title="lupa" width="128" height="96" class="aligncenter size-thumbnail wp-image-134" /></p>
<p><strong>Introdução</strong></p>
<p>Certa vez, após instalar o <a title="GLPI" href="http://www.glpi-project.org/" target="_blank">GLPI</a> (sistema de helpdesk), houve a necessidade de customiza-lo para ficar de acordo com as necessidades da empresa. O grande problema, era saber em qual arquivo encontrar o conteúdo que deveria ser alterado.<!--more--></p>
<p>Segue abaixo um exemplo de como efetuar a busca:</p>
<p># grep -R manaus /home/smith/ 2&#62;/dev/null &#124; cut -d: -f2 &#124; uniq</p>
<p>Vamos dissecar o comando:</p>
<p><strong><em>grep -R manaus /home/smith/</em></strong> &#8211; Procura recursivamente  pela palavra &#8220;manaus&#8221;, em todos arquivos a partir do diretório /home/smith.</p>
<p><em><strong>2&#62;/dev/null</strong></em> &#8211; Direciona as linhas de erro para /dev/null.</p>
<p><em><strong>&#124; (pipe)</strong></em> &#8211; Redireciona a saída do comando anterior (grep -R manaus /home/smith/ 2&#62;/dev/null), para a entrada do próximo comando.</p>
<p><em><strong>cut -d: -f2</strong></em> &#8211; O grep gera um arquivo no seguinte formato: /path/arquivo:conteúdo da linha<br />
Como queremos saber apenas qual arquivo contém a palavra &#8220;manaus&#8221;, utilizaremos o comando cut para tratar a saída. O cut lê a saída do comando anterior e seleciona apenas o segundo campo (-f2), separado pelo delimitar (-d) &#8220;dois pontos&#8221; (&#8220;:&#8221;), ignorando tudo que estiver depois do delimitador.</p>
<p><em><strong>uniq</strong></em> &#8211; Caso haja mais de uma ocorrência da palavra &#8220;manaus&#8221; em um mesmo arquivo, será exibida uma linha para cada ocorrência. O uniq remove as linhas duplicadas.</p>
<p>:wq!<br />
Andrey Smith</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Grepping lines with multiple matches]]></title>
<link>http://benbiddington.wordpress.com/2009/10/23/grepping-lines-with-multiple-matches/</link>
<pubDate>Fri, 23 Oct 2009 12:37:55 +0000</pubDate>
<dc:creator>benbiddington</dc:creator>
<guid>http://benbiddington.wordpress.com/2009/10/23/grepping-lines-with-multiple-matches/</guid>
<description><![CDATA[I want to filter log files by matching lines that contains all of  set of matches (I don&#8217;t wan]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I want to filter log files by matching lines that contains all of  set of matches (I don&#8217;t want to alternate them).</p>
<p>For example lines like:</p>
<pre style="padding-left:30px;">RawURL /1.2/user/authorize?ip=10.254.142.175&#38;method=GET</pre>
<p>I want to match lines that contain the terms &#8220;RawURL&#8221; and &#8220;/1.2/user/authorize?&#8221; without resorting to piping multiple greps:</p>
<pre style="padding-left:30px;">$ grep RawURL &#124; grep /1.2/user/authorize? *.txt</pre>
<p>This means I want a regexp like:</p>
<pre style="padding-left:30px;">RawURL.+\/1.2\/user\/authorize</pre>
<p>Translating to grep extended regex, this becomes:</p>
<pre style="padding-left:30px;">$ grep -E RawURL.+/1.2/user/authorize *.txt</pre>
<p>Note: There is no need to enforce non-greedy matching.</p>
<h3>Regular expressions, character classes and special characters</h3>
<p>The expression:</p>
<pre style="font:normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;padding-left:30px;">RawURL.+\/1.2\/user\/authorize</pre>
<p>Is not equivalent to:</p>
<pre style="padding-left:30px;">RawURL[.]+\/1.2\/user\/authorize</pre>
<p>Because in the second one, the special character &#8216;.&#8217; is no longer special. <a href="http://www.regular-expressions.info/charclass.html" target="_blank">Character classes</a> have all special characters turned off.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to check versions of gems in Heroku]]></title>
<link>http://alsargent.wordpress.com/2009/10/14/managing-gems-heroku/</link>
<pubDate>Wed, 14 Oct 2009 05:04:04 +0000</pubDate>
<dc:creator>Al Sargent</dc:creator>
<guid>http://alsargent.wordpress.com/2009/10/14/managing-gems-heroku/</guid>
<description><![CDATA[Recently I got stuck trying to fix a problem in Heroku, a slick cloud-based Ruby hosting service. Th]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Recently I got stuck trying to fix a problem in <a href="http://heroku.com/">Heroku</a>, a slick cloud-based Ruby hosting service. The problem involved gems that I had added to my app&#8217;s private gem repository. I had to check the versions of the gems in the repository, but Heroku&#8217;s documentation on <a href="http://docs.heroku.com/gems">gem management</a> didn&#8217;t provide any suggestions.</p>
<p>Turns out, the trick is to use <a href="http://docs.heroku.com/console">Heroku&#8217;s console command</a>, and then use the <a href="http://docs.rubygems.org/read/book/2">Ruby Gem command</a>. To open a new console session, fire up a terminal and enter:</p>
<blockquote><p>heroku console</p></blockquote>
<p>Then list the versions of the gems in your private repo, by enclosing the gem list command in backticks. (On Macs, the backtick key is in the upper left corner of the keyboard. I know, it took me a few seconds to find it as well.)</p>
<blockquote><p>`gem list`</p></blockquote>
<p>Since Heroku has <a href="http://installed-gems.heroku.com/">many built-in gems</a>, you&#8217;ll probably want to pipe through grep to find what you want:</p>
<blockquote><p>`gem list &#124; grep foo`</p></blockquote>
<p>And you&#8217;re off to the races!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Upload images to imageshack using bash]]></title>
<link>http://homeilja.wordpress.com/2009/10/14/upload-images-to-imageshack-using-bash/</link>
<pubDate>Tue, 13 Oct 2009 23:48:14 +0000</pubDate>
<dc:creator>ilja</dc:creator>
<guid>http://homeilja.wordpress.com/2009/10/14/upload-images-to-imageshack-using-bash/</guid>
<description><![CDATA[Found a nice little script on mroddball.wordpress.com. It uses curl to upload images to ImageShack: ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Found a nice little script on <a title="Mroddball" href="http://mroddball.wordpress.com/2009/10/13/upload-images-to-imageshack-from-command-line/" target="_blank">mroddball.wordpress.com</a>. It uses curl to upload images to <a title="ImageShack" href="http://imageshack.us/" target="_blank">ImageShack</a>:</p>
<pre class="brush: bash;">curl -H Expect: -F fileupload=&#34;@example.jpg&#34; -F xml=yes -# &#34;http://www.imageshack.us/index.php&#34;
</pre>
<p>If you invoke the above command the image will be uploaded and you get an xml file like this:</p>
<pre class="brush: xml;">&#60;?xml version=&#34;1.0&#34; encoding=&#34;iso-8859-1&#34;?&#62;&#60;links&#62;
    &#60;image_link&#62;http://img123.imageshack.us/img123/4567/example.jpg &#60;/image_link&#62;
    &#60;thumb_link&#62;http://img123.imageshack.us/img123/4567/example.th.jpg &#60;/thumb_link&#62;
    &#60;ad_link&#62;http://img123.imageshack.us/my.php?image=example.jpg &#60;/ad_link&#62;
    &#60;thumb_exists&#62;no&#60;/thumb_exists&#62;
    &#60;total_raters&#62;0&#60;/total_raters&#62;
    &#60;ave_rating&#62;0.0&#60;/ave_rating&#62;
    &#60;image_location&#62;img123/4567/example.jpg&#60;/image_location&#62;
    &#60;thumb_location&#62;img123/4567/example.th.jpg&#60;/thumb_location&#62;
    &#60;server&#62;img123&#60;/server&#62;
    &#60;image_name&#62;bricks.jpg&#60;/image_name&#62;
    &#60;done_page&#62;http://img123.imageshack.us/content.php?page=done&#38;amp;l=img123/4567/example.jpg&#60;/done_page&#62;
    &#60;resolution&#62;64x64&#60;/resolution&#62;
    &#60;filesize&#62;11771&#60;/filesize&#62;
    &#60;image_class&#62;r&#60;/image_class&#62;
&#60;/links&#62;
</pre>
<p>You can use <em>grep</em> to parse the image link from the xml file:</p>
<pre class="brush: bash;">curl -H Expect: -F fileupload=&#34;@example.jpg&#34; -F xml=yes -# &#34;http://www.imageshack.us/index.php&#34; &#124; grep image_link &#124; grep -o  http[^\&#60;]*
</pre>
<p>You could also use <em>find</em>, <em>for</em> etc. to upload as many pictures as you like at the same time. The whole script is located on <a title="ImageShack script on pastebin" href="http://pastebin.com/f46bd93ab" target="_blank">pastebin</a>. Visit <a title="Mroddball" href="http://mroddball.wordpress.com/2009/10/13/upload-images-to-imageshack-from-command-line/" target="_blank">mroddball.wordpress.com</a> for further information.</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[El origen de GREP en UNIX]]></title>
<link>http://cambrico.info/2009/10/11/el-origen-de-grep-en-unix/</link>
<pubDate>Sun, 11 Oct 2009 15:24:52 +0000</pubDate>
<dc:creator>Ruben Antonio Fernández</dc:creator>
<guid>http://cambrico.info/2009/10/11/el-origen-de-grep-en-unix/</guid>
<description><![CDATA[                En mi posting anterior hice referencia al comando GREP contenido en Linux. Es mi int]]></description>
<content:encoded><![CDATA[                En mi posting anterior hice referencia al comando GREP contenido en Linux. Es mi int]]></content:encoded>
</item>
<item>
<title><![CDATA[Encode .mov files with FFMPEG H246  ]]></title>
<link>http://redbeardtechnologies.wordpress.com/2009/10/09/encode-mov-files-with-ffmpeg-h246/</link>
<pubDate>Fri, 09 Oct 2009 15:24:57 +0000</pubDate>
<dc:creator>redbeardtechnologies</dc:creator>
<guid>http://redbeardtechnologies.wordpress.com/2009/10/09/encode-mov-files-with-ffmpeg-h246/</guid>
<description><![CDATA[Hello, I had a project today to mass encode a bunch of videos that are in the .mov format. The requi]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hello,</p>
<p>I had a project today to mass encode a bunch of videos that are in the .mov format. The requirements for the job specify if the video file is 640&#215;480 resolution just encode the video with the H264 codec. If the video is not 640&#215;480 I must resize the video to 720&#215;480. I wrote a little bash script to help me sort through the files and encode them.</p>
<pre>#!/bin/bash
files="$(ls *\.mov)"
for movie_file in $files ; do
    if [ -f "${movie_file}" ]
    then
        video_size="$(ffmpeg -i "${movie_file}" 2&#62;&#38;1 &#124; grep -m 1 Video &#124;  grep -oE "[[:digit:]]{3,4}x[[:digit:]]{3,4}")"
        if [ "${video_size}" = "640x480" ]
        then
            ffmpeg -i ${movie_file} -acodec libfaac -r 30 -ac 2 -vcodec libx264 -vpre hq -crf 22 -sameq -threads 0 "${movie_file}.mp4"
        else
            ffmpeg -i ${movie_file} -acodec libfaac -r 30 -ac 2 -vcodec libx264 -vpre hq -crf 22 -sameq -threads 0 -s 720x480 "${movie_file}.mp4"
        fi
        qt-faststart ${movie_file}.mp4 ${movie_file}.fs.mp4
    fi
done</pre>
<p>Let me explain how the program works for those unfamiliar with Bash</p>
<pre>files="$(ls *\.mov)"</pre>
<p>The command ls gets a directory listing with only the .mov files and saves it into the variable &#8220;files&#8221;. In this example I am only looking for files with the .mov file extension.</p>
<pre>for movie_file in $files ; do
 [stuff]
done</pre>
<p>The for loop lets my program iterate through the files available in the directory that have a .mov file extension.</p>
<pre>if [ -f "${movie_file}" ]</pre>
<p>This just checks that the file is valid and exists.</p>
<pre>
<pre>video_size="$(ffmpeg -i "${movie_file}" 2&#62;&#38;1 &#124; grep -m 1 Video &#124;  grep -oE "[[:digit:]]{3,4}x[[:digit:]]{3,4}")"</pre>
</pre>
<p>This command is essential for identifying the video resolution. I use ffmpeg to get information about the file and then use grep to determine the resolution using a regular expression. It is important to note that the grep command &#8220;grep -m 1 Video&#8221; only matches the first resolution found. Some times ffmpeg will list multiple video resolutions. If the resolution is listed more than once the bash program fails.</p>
<pre>
<pre>
<pre>ffmpeg -i ${movie_file} -acodec libfaac -r 30 -ac 2 -vcodec libx264 -vpre hq -crf 22 -sameq -threads 0 "${movie_file}.mp4"</pre>
</pre>
</pre>
<p>This command converts the video file using the H264 codec. I try to retain the same quality as the original video using the parameters shown above.</p>
<pre>
<pre>
<pre>
<pre>qt-faststart ${movie_file}.mp4 ${movie_file}.fs.mp4</pre>
</pre>
</pre>
</pre>
<p>qt-faststart puts the meta data contained in the video file in the head of the file. The meta data by default is contained in the tail of the file. The tail meta data messes up flowplayer or the flash player you are using because video must be downloaded before the video player can obtain the meta data about the video. Google search on the term &#8220;<strong>moov atom</strong>&#8221; to learn more.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to get your external IP address using bash]]></title>
<link>http://homeilja.wordpress.com/2009/10/08/how-to-get-your-external-ip-address-using-bash/</link>
<pubDate>Thu, 08 Oct 2009 13:29:11 +0000</pubDate>
<dc:creator>ilja</dc:creator>
<guid>http://homeilja.wordpress.com/2009/10/08/how-to-get-your-external-ip-address-using-bash/</guid>
<description><![CDATA[If you are behind a router, ifconfig won&#8217;t give you your external IP address. As a possible so]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>If you are behind a router, <a title="ifconfig manpage" href="http://linux.die.net/man/8/ifconfig" target="_blank">ifconfig</a> won&#8217;t give you your external IP address. As a possible solution you can (w)get it from <a title="http://checkip.dyndns.org/" href="http://checkip.dyndns.org/" target="_blank">http://checkip.dyndns.org/</a> and grep your external IP from the html file:</p>
<pre class="brush: bash;"> wget http://checkip.dyndns.org/ -qO - &#124; grep -Eo '\&#60;[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\&#62;'
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[findgrep: Rekursive Textsuche (shell script)]]></title>
<link>http://linuxnetz.wordpress.com/2009/10/03/findgrep0-2/</link>
<pubDate>Sat, 03 Oct 2009 11:23:17 +0000</pubDate>
<dc:creator>linuxnetzer</dc:creator>
<guid>http://linuxnetz.wordpress.com/2009/10/03/findgrep0-2/</guid>
<description><![CDATA[Ende Juli veröffentlichte ich das Skript &#8220;findgrep&#8221;, das mit Hilfe von &#8220;find]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Ende Juli veröffentlichte ich das Skript &#8220;findgrep&#8221;, das mit Hilfe von &#8220;find&#8221; und &#8220;grep&#8221; Verzeichnisse rekursiv nach Textmustern durchsucht.</strong></p>
<div class="wp-caption alignleft" style="width: 136px"><a href="http://commons.wikimedia.org/wiki/File:Lupe_kl.jpg"><img src="http://upload.wikimedia.org/wikipedia/commons/5/50/Lupe_kl.jpg" alt="Für Lizenz: Bild klicken" width="126" height="126" /></a><p class="wp-caption-text"> Lizenz:Creative Commons Attribution ShareAlike 3.0; (click pic for details)</p></div>
<p>Der dazu erschienene Artikel (samt Skript für die bash) hat sich inzwischen zu einem der meistaufgerufenen Artikel  dieses Blogs gemausert. Auch bei den Suchanfragen, über die dieses Blog gefunden wird, stehen Ausdrücke wie &#8220;find und grep rekursiv&#8221; oft ganz oben auf der Hitliste. Bevor ich das Skript zusammengeschustert hatte, war ich auch eine gute Weile mit Recherche beschäftigt, ohne auf die Schnelle eine passende Lösung zu finden.</p>
<p>Deshalb habe ich das Skript in den letzten Wochen auf meinem Klapprechner  überarbeitet. Das Resultat, &#8220;findgrep Version 0.2&#8243; kann weiter unten heruntergeladen werden.</p>
<div id="attachment_804" class="wp-caption aligncenter" style="width: 458px"><img class="size-full wp-image-804" title="findgrep4_start" src="http://linuxnetz.wordpress.com/files/2009/09/findgrep4_start1.png" alt="findgrep v4: Verzeichnisse rekursiv nach Text durchsuchen" width="448" height="270" /><p class="wp-caption-text">findgrep v 0.2: Verzeichnisse rekursiv nach Text durchsuchen</p></div>
<p><strong>Verbesserungen:</strong></p>
<ul>
<li>Die gefilterten Ergebnisse werden ja in einer Textdatei (Variable $SAVEFILE) gespeichert. War diese Datei jedoch unterhalb des Suchverzeichnisses angesiedelt, suchte sich findgrep einen Wolf, da es die bereits gefundenen Ergebnisse erneut als Treffer anzeigte. Dieser Bug wurde behoben.</li>
<li>Bisher musste der Nutzer nach jedem Start des Programms den Suchpfad angeben. Zusätzlich hat der Nutzer nun die Möglichkeit, durch &#8220;ENTER&#8221; das Standardverzeichnis zu bestätigen (Standard: /var/log)  Zum Ändern einfach die Variable $SEARCHDIR im Skript anpassen.</li>
<li>Sowohl bei der Auswahl als auch bei der Präsentation der Ergebnisse wurde das Programm grafisch anschaulicher aufpoliert</li>
<li>findgrep zeigt nun die Anzahl der gefundenen Matches an</li>
</ul>
<div id="attachment_814" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-814" title="findgrep4_resultss" src="http://linuxnetz.wordpress.com/files/2009/09/findgrep4_resultss1.png" alt="findgrep: Suche nach &#34;warning&#34; in /var/log beendet ..." width="450" height="276" /><p class="wp-caption-text">findgrep: Suche nach &#34;warning&#34; in /var/log beendet ...</p></div>
<p><strong><span style="color:#000000;">Download findgrep v 0.2:</span> </strong>Bitte <a href="http://tinyurl.com/ybpxs3s" target="_blank">hier klicken</a> und mit copy und paste holen. Rechtsklick und &#8220;Speichern unter &#8230;&#8221; funktioniert nicht.</p>
<p><strong></strong>Das Skript ist für Ubuntu getestet. Manche Versionen von grep kennen die Option &#8220;color&#8221; nicht und brechen das Skript mit Fehlermeldung ab. Äh, ach ja: Der nette junge Herr oben bin nicht ich. Ich fand das Bild nur passend zum Thema und habe es auf <a href="http://commons.wikimedia.org/wiki/Main_Page">Wikimedia </a>gefunden.</p>
<p><a href="http://linuxnetz.wordpress.com/?s=findgrep">Alle findgrep Artikel</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to Change MAC Address]]></title>
<link>http://miteshjlinuxtips.wordpress.com/2009/09/30/how-to-change-mac-address/</link>
<pubDate>Wed, 30 Sep 2009 07:02:36 +0000</pubDate>
<dc:creator>miteshsjat</dc:creator>
<guid>http://miteshjlinuxtips.wordpress.com/2009/09/30/how-to-change-mac-address/</guid>
<description><![CDATA[Changing MAC address of a machine is called spoofing a MAC address or faking a MAC address. In linux]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Changing MAC address of a machine is called spoofing a MAC address or faking a MAC address. In linux, you can <b>change MAC address</b> of your machine. This is how it is done.</p>
<p>First find the physical MAC address of your machine by running the following command :<br />
<code><br />
</code>
<pre>$ <span style="color:rgb(0,102,0);">ifconfig -a &#124; grep HWaddr</span>
eth0  Link encap:Ethernet HWaddr <span style="color:blue;"></span><span style="color:rgb(0,0,153);">00:1f:f3:cc:c2:f9</span>
</pre>
<p>The hexadecimal numbers in <span style="color:blue;">blue</span> denote my machine&#8217;s MAC address. Yours will be different. </p>
<p>Next, login as root in Linux and enter the following commands -</p>
<p><code><br />
</code>
<pre>
# <span style="color:rgb(0,102,0);">ifconfig eth0 down</span>
# <span style="color:rgb(0,102,0);">ifconfig eth0 hw ether</span> <span style="color:blue;">00:11:22:33:44:55</span>
#<span style="color:rgb(0,102,0);"> ifconfig eth0 up</span>
# <span style="color:rgb(0,102,0);">ifconfig eth0 &#124; grep HWaddr</span>
</pre>
<p>Note above that I have changed the MAC address to a different number highlighted in blue.<span style="color:blue;"><span style="font-family:monospace;"> </span>00:11:22:33:44:55</span><span style="font-family:monospace;"> </span><code></code> is the new MAC address I have provided for my Linux machine. You can choose any 48 bits hexadecimal address as your MAC address.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Restricting pattern replacement to specific lines?]]></title>
<link>http://peeterjoot.wordpress.com/2009/09/29/restricting-pattern-replacement-to-specific-lines/</link>
<pubDate>Tue, 29 Sep 2009 16:55:47 +0000</pubDate>
<dc:creator>peeterjoot</dc:creator>
<guid>http://peeterjoot.wordpress.com/2009/09/29/restricting-pattern-replacement-to-specific-lines/</guid>
<description><![CDATA[We&#8217;ve had a marketing driven name change that impacts a lot of internal error strings in our c]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>We&#8217;ve had a marketing driven name change that impacts a lot of internal error strings in our code in a silly way, and I&#8217;ve got a lot of stuff like the following output</p>
<pre># grep -n '".* BA' *C
foo.C:1486:                       "Unexpected BA error - panic",
foo.C:1561:                       "Unexpected BA error - panic",
foo.C:1569:                       "Unexpected BA error",
...</pre>
<p>All these &#8216;BA&#8217;s have to be changed to &#8216;BF&#8217;.</p>
<p>Ideally no customers would ever see these developer centric messages, but they will be in our logfiles, and potentially visible and confusing.</p>
<p>It&#8217;s not too hard to replace these, but there&#8217;s a lot of them.  I&#8217;ve had this kind of task before, and have done it using hacky throw away command line &#8220;one-liners&#8221; like the following:</p>
<pre>for i in `cut -f1,2 -d: grepoutput` ; do
   f=`echo $i &#124; cut -f1 -d:`
   l=`echo $i &#124; cut -f2 -d:`
   vim +$l +:'s/\/BF/g' +wq $i
done</pre>
<p>Okay, it&#8217;s not a one liner as above since I&#8217;ve formatted this with newlines instead of semicolons, but when tossing off throwaway bash/ksh for loop stuff like this I usually do it as a one liner.  This bash loop is easy enough to write, but messy and also fairly easy to get wrong.  I&#8217;m tired of doing this over and over again.</p>
<p>It seemed to me that it was time to code up something that I can tweak for automated tasks like this, and wrote the perl script below that consumes grep -n ouput (ie. file:lineno:stuff output), and makes the desired replacements, whatever they are.  I&#8217;ve based this strictly on the grep output because the unrestricted replacements could be dangerous and I wanted to visually verify that all the replacement sites were appropriate.</p>
<pre>
#!/usr/bin/perl

my %lines ;

while (&#60;&#62;)
{
   chomp ;

   /^(.*?):(.*?):/ or die ;

   $lines{$1} .= ",$2" ;
}

foreach (keys %lines)
{
   process_file( $_, split(/,/, $lines{$_} ) ) ;
}

exit ;

sub process_file
{
   my ($filename, @n) = @_ ;

   my %thisLines = map { $_ =&#62; 1 } @n ;

   open my $fhIn, "$filename.2" or die ;

   my $lineno = 0 ;
   while ( &#60;$fhIn&#62; )
   {
      $lineno++ ;

      if ( exists($thisLines{$lineno}) )
      {
         # word delimiters to replace BA but not BASH nor ABAB, ...
         s/\bBA\b/BF/g ;
      }

      print $fhOut $_ ;
   }

   close $fhIn ;
   close $fhOut ;
}
</pre>
<p>This little script, while certainly longer than the one-liner method, is fairly straightforward and easy to modify for other similar ad-hoc replacement tasks later.  However, I have to wonder if there&#8217;s an easier way?</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[awk] Print selective columns and watch for changes]]></title>
<link>http://nixtricks.wordpress.com/2009/09/26/awk-print-selective-columns-and-watch-for-changes/</link>
<pubDate>Sat, 26 Sep 2009 09:29:57 +0000</pubDate>
<dc:creator>kousik</dc:creator>
<guid>http://nixtricks.wordpress.com/2009/09/26/awk-print-selective-columns-and-watch-for-changes/</guid>
<description><![CDATA[Print columns 1, 5 and then 2, put a colon, and then print column 10 of a line that matches pattern ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Print columns 1, 5 and then 2, put a colon, and then print column 10 of a line that matches <em>pattern</em> from the file <em>columns.txt</em>:</p>
<div style="border:1px dotted black;padding:1em;"><code> $ awk '/<em>pattern</em>/ {print $1, $5, $2, ": ", $10}' <em>columns.txt</em><br />
</code></div>
<p><span style="color:#ffffff;">.</span><br />
<strong>Protecting the special meaning of the single quotes and curly braces</strong><br />
I came across this situation when I was trying to <code>watch</code> the above command as well as two other commands (say, <code>command1</code> and <code>command2</code>) at the same time. The correct way to do that is by properly protecting the meaning of the special characters in the above <code>awk</code> invocation:</p>
<div style="border:1px dotted black;padding:1em;"><code> $ watch -d -n 20 "command1; command2; awk '"'/<em>pattern</em>/ {print $1, $5, $2, ": ", $10}'"' <em>columns.txt</em>"</code></div>
<p>.<br />
<strong>N.B.</strong> The &#8220;<code>-d</code>&#8221;flag highlights the changes, whereas the &#8220;<code>-n 20</code>&#8221; flag causes the above to watch every 20 seconds.</p>
<p>Just for the heck of it, let me put the full command that I was actually using:</p>
<div style="border:1px dotted black;padding:1em;"><code> $ watch -d -n 20 "ps aux &#124; grep -i columbus &#124; grep -v grep &#38;&#38; echo;  tail WORK/ciudgsm &#38;&#38; echo &#38;&#38; grep bond output.log &#124; tail -13 &#38;&#38; echo &#38;&#38; awk '"'/state # 1/ {print $3,$4,$5,": ", $10}'"' output.log &#38;&#38; echo; awk '"'/state # 2/ {print $3,$4,$5,": ", $10}'"' output.log &#38;&#38; head curr_iter"<br />
</code></div>
<p>(suggestions for making the above shorter, other than by aliasing, are most welcome!).</p>
<p><strong>Reference: </strong> <a href="http://www.vectorsite.net/tsawk.html">here</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[grep] grep, egrep and fgrep ]]></title>
<link>http://nixtricks.wordpress.com/2009/09/26/grep-grep-egrep-and-fgrep/</link>
<pubDate>Sat, 26 Sep 2009 06:44:31 +0000</pubDate>
<dc:creator>kousik</dc:creator>
<guid>http://nixtricks.wordpress.com/2009/09/26/grep-grep-egrep-and-fgrep/</guid>
<description><![CDATA[I always get confused about various flavors of grep. Here&#8217;s a summary to shine some light: (ma]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I always get confused about various flavors of <code>grep</code>. Here&#8217;s a summary to shine some light: (<code>man grep</code>  to know more!)</p>
<ul>
<li> <code>egrep</code> or <code>grep -E</code> (in linux only) is extended grep where additional regular expression metacharacters have been added like <code>+, ?, &#124; and ()</code></li>
<li><code>fgrep</code> or <code>grep -F  </code> (in linux only) is fixed or fast grep and behaves as grep but does not recognize any regular expression metacharacters as being special.</li>
</ul>
</div>]]></content:encoded>
</item>

</channel>
</rss>
