<?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>KarkomaOnline &#187; Tips and Tricks</title>
	<atom:link href="http://www.karkomaonline.com/index.php/category/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.karkomaonline.com</link>
	<description>a Blog for SysAdmins and Unix stuff in general</description>
	<lastBuildDate>Fri, 30 Jul 2010 17:38:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Description of the file system hierarchy</title>
		<link>http://www.karkomaonline.com/index.php/2009/08/description-of-the-file-system-hierarchy/</link>
		<comments>http://www.karkomaonline.com/index.php/2009/08/description-of-the-file-system-hierarchy/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 22:14:57 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Unix facts]]></category>
		<category><![CDATA[File system]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/?p=269</guid>
		<description><![CDATA[Description of the file system hierarchy]]></description>
			<content:encoded><![CDATA[<blockquote><p>man hier</p></blockquote>
<p> <img src='http://www.karkomaonline.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2009/08/description-of-the-file-system-hierarchy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash script: effectively check if a filesystem is mounted</title>
		<link>http://www.karkomaonline.com/index.php/2009/08/bash-script-effectively-check-if-a-filesystem-is-mounted/</link>
		<comments>http://www.karkomaonline.com/index.php/2009/08/bash-script-effectively-check-if-a-filesystem-is-mounted/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 21:39:41 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/?p=265</guid>
		<description><![CDATA[Check if file system is mounted]]></description>
			<content:encoded><![CDATA[<p>Whenever you want to check if a file system is mounted and perform some action in you script based on this, the simplest and most accurate way to do it in Linux is to check <em>/proc/mounts</em>:</p>
<blockquote><p>
if grep -qs &#8216;/mnt/sda2&#8242; /proc/mounts; then<br />
     echo &#8220;fs mounted&#8221;<br />
else<br />
     echo &#8220;fs not mounted&#8221;<br />
fi
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2009/08/bash-script-effectively-check-if-a-filesystem-is-mounted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to disable IPv6 in Debian</title>
		<link>http://www.karkomaonline.com/index.php/2009/04/how-to-disable-ipv6-in-debian/</link>
		<comments>http://www.karkomaonline.com/index.php/2009/04/how-to-disable-ipv6-in-debian/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 17:08:32 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Linux Debian]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[IPv6]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/?p=259</guid>
		<description><![CDATA[Disable IPv6 in Debian]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently installed a new <a href="http://www.openldap.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.openldap.org/?referer=');">LDAP</a> server on <a href="http://www.debian.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.debian.org/?referer=');">Debian</a> Lenny and I wanted to disable <a href="http://en.wikipedia.org/wiki/IPv6" target="_blank" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/IPv6?referer=');">IPv6</a> as it is unnecessary for me in this moment. With <em>netstat</em> I checked the listening processes:</p>
<blockquote><p>netstat -tunlp</p></blockquote>
<p><code>Active Internet connections (only servers)<br />
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name<br />
tcp        0      0 0.0.0.0:389             0.0.0.0:*               LISTEN      2226/slapd<br />
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2215/sshd<br />
tcp6       0      0 :::389                  :::*                    LISTEN      2226/slapd<br />
tcp6       0      0 :::22                   :::*                    LISTEN      2215/sshd</code></p>
<p>and <em>lsmod</em> showed something like this:</p>
<p><code>Module                  Size  Used by<br />
ipv6                  235364  12<br />
...</code></p>
<p>So, to disable IPv6 I changed <em>/etc/modprobe.d/aliases</em>:<br />
<code>...<br />
# alias net-pf-10 ipv6<br />
# Disable ipv6<br />
alias net-pf-10 off<br />
alias ipv6 off<br />
...</code></p>
<p>I also disabled these lines in <em>/etc/hosts</em> to avoid confusions:</p>
<p><code>...<br />
## The following lines are desirable for IPv6 capable hosts<br />
#::1     localhost ip6-localhost ip6-loopback<br />
#fe00::0 ip6-localnet<br />
#ff00::0 ip6-mcastprefix<br />
#ff02::1 ip6-allnodes<br />
#ff02::2 ip6-allrouters<br />
#ff02::3 ip6-allhosts</code></p>
<p>Finally I restarted the server.</p>
<blockquote><p>shutdown -r now</p></blockquote>
<p>Now the situation is like this:</p>
<blockquote><p>netstat -tunlp</p></blockquote>
<p><code>Active Internet connections (only servers)<br />
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name<br />
tcp        0      0 0.0.0.0:389             0.0.0.0:*               LISTEN      2233/slapd<br />
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2216/sshd</code></p>
<blockquote><p>lsmod|grep ipv6</p></blockquote>
<p><code>...</code></p>
<p>No IPv6.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2009/04/how-to-disable-ipv6-in-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dig: basic usage</title>
		<link>http://www.karkomaonline.com/index.php/2009/04/dig-basic-usage/</link>
		<comments>http://www.karkomaonline.com/index.php/2009/04/dig-basic-usage/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 21:21:35 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[dig]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/?p=214</guid>
		<description><![CDATA[Today we are going to take a quick look at dig. According to the man pages: dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS [...]]]></description>
			<content:encoded><![CDATA[<p>Today we are going to take a quick look at dig. According to the man pages:</p>
<blockquote><p>dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output.</p></blockquote>
<p>Let&#8217;s see how to lookup the DNS servers for the domain karkomaonline.com:</p>
<p><code>dig karkomaonline.com -t ns</code></p>
<p>The <em>-t</em> option specifies the query type (<em>a</em>, <em>any</em>, <em>mx</em>, <em>ns</em>, <em>txt</em>&#8230; ), being <em>a</em> the default. The <em>-t ns</em> option will look-up the Name Servers for the domain karkomaonline.com. You should get something like this:</p>
<p><code>; &lt;&lt;&gt;&gt; DiG 9.4.2-P2 &lt;&lt;&gt;&gt; karkomaonline.com -t ns<br />
;; global options:  printcmd<br />
;; Got answer:<br />
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 4825<br />
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1<br />
</code><br />
<code><br />
;; QUESTION SECTION:<br />
;karkomaonline.com.        IN    NS<br />
</code><br />
<code><br />
;; ANSWER SECTION:<br />
karkomaonline.com.    172800    IN    NS    dns010.d.register.com.<br />
karkomaonline.com.    172800    IN    NS    dns024.c.register.com.<br />
karkomaonline.com.    172800    IN    NS    dns071.a.register.com.<br />
karkomaonline.com.    172800    IN    NS    dns150.b.register.com.<br />
</code><br />
<code><br />
;; ADDITIONAL SECTION:<br />
dns010.d.register.com.    48    IN    A    216.21.236.10<br />
</code><br />
<code><br />
;; Query time: 172 msec<br />
;; SERVER: 192.168.1.9#53(192.168.1.9)<br />
;; WHEN: Wed Apr 15 22:46:35 2009<br />
;; MSG SIZE  rcvd: 152<br />
</code></p>
<p>The interesting part is the ANSWER SECTION, that lists the name servers for the mentioned domain. You can get a shorter output of the same command:</p>
<p><code>dig karkomaonline.com -t ns +short</code></p>
<p><code>dns010.d.register.com.<br />
dns071.a.register.com.<br />
dns024.c.register.com.<br />
dns150.b.register.com.</code></p>
<p>Now look up the mail servers for the same domain:</p>
<p><code>dig karkomaonline.com -t mx</code></p>
<p><code>...<br />
;; ANSWER SECTION:<br />
karkomaonline.com.    86400    IN    MX    0 mailhost.karkomaonline.com.<br />
...</code></p>
<p>From the output of the first example you can see that by default dig queried my internal DNS server (configured in <em>/etc/resolv.conf</em>):</p>
<p><code>...<br />
;; SERVER: 192.168.1.9#53(192.168.1.9)<br />
...<br />
</code><br />
You can change this behaviour by instructing dig to query a specific name server:</p>
<p><code>dig @dns010.d.register.com karkomaonline.com -t mx</code></p>
<p><code>...<br />
;; ANSWER SECTION:<br />
karkomaonline.com.    86400    IN    MX    0 mailhost.karkomaonline.com.<br />
</code><br />
<code><br />
;; ADDITIONAL SECTION:<br />
mailhost.karkomaonline.com. 86400 IN    A    94.75.208.171<br />
</code><br />
<code><br />
;; Query time: 181 msec<br />
;; SERVER: 216.21.236.10#53(216.21.236.10)<br />
...<br />
</code></p>
<p>Note that the queried server now is 216.21.236.10.</p>
<p><strong>More info:</strong>:</p>
<ul>
<li><a href="http://www.manpagez.com/man/1/dig/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.manpagez.com/man/1/dig/?referer=');">man page</a></li>
<li><a href="http://www.madboa.com/geek/dig/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.madboa.com/geek/dig/?referer=');"> howto</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2009/04/dig-basic-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ISO image as a filesystem</title>
		<link>http://www.karkomaonline.com/index.php/2009/01/iso-image-as-a-filesystem/</link>
		<comments>http://www.karkomaonline.com/index.php/2009/01/iso-image-as-a-filesystem/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 17:59:37 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[mount]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/?p=196</guid>
		<description><![CDATA[If you want to mount an ISO image as a filesystem, simply proceed as follows: mkdir /mnt/iso0 mount -o loop -t iso9660 /tmp/debian-40r6-amd64-netinst.iso  /mnt/iso0]]></description>
			<content:encoded><![CDATA[<p>If you want to mount an ISO image as a filesystem, simply proceed as follows:</p>
<blockquote><p>
mkdir /mnt/iso0<br />
mount -o loop -t iso9660 /tmp/debian-40r6-amd64-netinst.iso  /mnt/iso0
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2009/01/iso-image-as-a-filesystem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>System stats with saidar</title>
		<link>http://www.karkomaonline.com/index.php/2008/04/system-stats-with-saidar/</link>
		<comments>http://www.karkomaonline.com/index.php/2008/04/system-stats-with-saidar/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 10:38:50 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Linux Debian]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[saidar]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/?p=183</guid>
		<description><![CDATA[saidar is a top like tool. It provides a curses based interface for viewing system statistics such as network I/O, disk I/O, CPU, memory and more. The core of the functionality is provided by the libstatgrab library: libstatgrab is a library that provides cross platform access to statistics about the system on which it's run. [...]]]></description>
			<content:encoded><![CDATA[<p>saidar is a top like tool. It provides a curses based interface for viewing system statistics such as network I/O, disk I/O, CPU, memory and more. The core of the functionality is provided by the <a href="http://www.i-scream.org/libstatgrab/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.i-scream.org/libstatgrab/?referer=');">libstatgrab</a> library:</p>
<p><code>libstatgrab is a library that provides cross platform access to statistics about the system on which it's run. It's written in C and presents a selection of useful interfaces which can be used to access key system statistics. The current list of statistics includes CPU usage, memory utilisation, disk usage, process counts, network traffic, disk I/O, and more.</code></p>
<p>On a Debian system install the package as usual:</p>
<blockquote><p>apt-get install saidar</p></blockquote>
<p>and then run:</p>
<blockquote><p>saidar</p></blockquote>
<p><a href='http://www.karkomaonline.com/wp-content/uploads/2008/04/saidar2.png'><img src="http://www.karkomaonline.com/wp-content/uploads/2008/04/saidar2.png" alt="Saidar in action" title="saidar2" width="500" height="307" class="aligncenter size-full wp-image-185" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2008/04/system-stats-with-saidar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serial terminal support in GRUB</title>
		<link>http://www.karkomaonline.com/index.php/2008/02/serial-terminal-support-in-grub/</link>
		<comments>http://www.karkomaonline.com/index.php/2008/02/serial-terminal-support-in-grub/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 08:45:13 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Grub]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/index.php/2008/02/09/serial-terminal-support-in-grub/</guid>
		<description><![CDATA[In some situations it is very useful to have the possibility to access the GRUB boot menu from a serial line. For example you could remotely reboot your machine with the new kernel you just compiled. In my case I have a couple of remote machines linked together by a serial cable. I can log [...]]]></description>
			<content:encoded><![CDATA[<p>In some situations it is very useful to have the possibility to access the GRUB boot menu from a serial line. For example you could remotely reboot your machine with the new kernel you just compiled.</p>
<p>In my case I have a couple of remote machines linked together by a serial cable. I can log into machine A via ssh and get the Grub menu of machine B through <a href="http://alioth.debian.org/projects/minicom/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/alioth.debian.org/projects/minicom/?referer=');">minicom</a>. Thus I can boot whatever OS/kernel I want as if I were in front of the machine. Kind of KVM IP for the rest of us.</p>
<p>Simply add this to Grub&#8217;s menu.lst:</p>
<blockquote><p> serial &#8211;unit=0 &#8211;speed=9600 &#8211;word=8 &#8211;parity=no &#8211;stop=1<br />
terminal serial</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2008/02/serial-terminal-support-in-grub/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: quick replacement</title>
		<link>http://www.karkomaonline.com/index.php/2007/12/mysql-quick-replacement/</link>
		<comments>http://www.karkomaonline.com/index.php/2007/12/mysql-quick-replacement/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 04:45:44 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/index.php/2007/12/06/mysql-quick-replacement/</guid>
		<description><![CDATA[Say that you have a table called myTable with several rows and a column called URL that contains the IP address of a log server. Now imagine that you want to change the value of URL so IP address is substituted by the server name. One way to do that is as follows: use dbname [...]]]></description>
			<content:encoded><![CDATA[<p>Say that you have a table called myTable with several rows and a column called URL that contains the IP address of a log server. Now imagine that you want to change the value of URL so IP address is substituted by the server name. One way to do that is as follows:</p>
<blockquote><p>use dbname</p>
<p>update myTbl set URL=replace(URL,&#8217;172.16.1.10&#8242;,&#8217;logserver&#8217;);</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2007/12/mysql-quick-replacement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenSSH: simplifying logins</title>
		<link>http://www.karkomaonline.com/index.php/2007/12/openssh-simplifying-logins/</link>
		<comments>http://www.karkomaonline.com/index.php/2007/12/openssh-simplifying-logins/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 04:21:09 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[OpenSSH]]></category>

		<guid isPermaLink="false">http://www.karkomaonline.com/index.php/2007/12/06/openssh-simplifying-logins/</guid>
		<description><![CDATA[OpenSSH provides a per-user configuration file usually located in ~/.ssh/config. This file can help ease your life as Sysadmin. Let&#8217;s say that you frequently connect to a server in this way: ssh admin@boring-servername.boring-domain.com With OpenSSH there is an easy way to do the job. Edit or create a config file: vi ~/.ssh/config and then add [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.openbsd.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.openbsd.org/?referer=');">OpenSSH</a> provides a per-user configuration file usually located in ~/.ssh/config. This file can help ease your life as Sysadmin. Let&#8217;s say that you frequently connect to a server in this way:</p>
<blockquote><p>ssh admin@boring-servername.boring-domain.com</p></blockquote>
<p>With OpenSSH there is an easy way to do the job. Edit or create a <em>config</em> file:</p>
<blockquote><p>vi ~/.ssh/config</p></blockquote>
<p>and then add the following:</p>
<blockquote><p> Host servername<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User admin<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HostName boring-servername.boring-domain.com</p></blockquote>
<p>Where Host is the alias for the remote server you want to connect to, HostName is the full name of the remote server and User is the login name.</p>
<p><strong>References</strong>:</p>
<ul>
<li>man <a href="http://www.openbsd.org/cgi-bin/man.cgi?query=ssh_config" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.openbsd.org/cgi-bin/man.cgi?query=ssh_config&amp;referer=');">ssh_config </a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2007/12/openssh-simplifying-logins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl on the command line</title>
		<link>http://www.karkomaonline.com/index.php/2007/05/perl-on-the-command-line/</link>
		<comments>http://www.karkomaonline.com/index.php/2007/05/perl-on-the-command-line/#comments</comments>
		<pubDate>Sun, 27 May 2007 10:55:59 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.karkoma.info/index.php/2007/05/27/perl-on-the-command-line/</guid>
		<description><![CDATA[Perl, you know perl, is not just a jewel for scripting, it &#8216;s also a potent onliner. The magic trick is the diamond: perl -e &#8216;while (){print}&#8217; file1 says perl &#8220;keep on as long as you read something in the standard in&#8221;, in the case of the example above, &#8220;print the line&#8221; &#8230; and each [...]]]></description>
			<content:encoded><![CDATA[<p>Perl, you know perl, is not just a jewel for scripting, it &#8216;s also a potent onliner.</p>
<p>The magic trick is the diamond:</p>
<blockquote><p>perl -e &#8216;while (){print}&#8217; file1</p></blockquote>
<p>says perl &#8220;keep on as long as you read something in the standard in&#8221;, in the case of the example above, &#8220;print the line&#8221; &#8230; and each line goes in the memory but not the whole file: you have a powerful stream editor.</p>
<p>The &#8221; -e&#8221; switch says to perl that what follows in the command line between the single quotations is a script and not a script file name.</p>
<p>But you can have it quicklier :</p>
<blockquote><p>perl -ane &#8216;print&#8217; file1</p></blockquote>
<p>The switches &#8220;-ane&#8221; do the &#8220;while stuff&#8221; for you. It says &#8220;do a while () loop&#8221; (-n) &#8220;and split each record in the @F array&#8221; (-a), I haven&#8217;t used the array yet.<br />
Perl has a difficulty : you can implicit everything. Some guys abuse of it in scripting, like spirits, but it&#8217;s good for an onliner.</p>
<p>This line will print file1. Great (in fact implicit in &#8220;print $_&#8221; ; $_ is the variable where perl puts what you do not explicit). Printing is great but let do some awkish things :</p>
<blockquote><p>perl -ane &#8216;/$m[aiy]/ &amp;&amp; print $_&#8217;</p></blockquote>
<p>That will print the lines that contain $ma, $mi or $my, (have a look at the article from karkoma about sed), patterns in perl are like sed&#8217;s ones but larger. Take a look at the <a href="http://perldoc.perl.org/perlreftut.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/perldoc.perl.org/perlreftut.html?referer=');">tutorial of perl for pattern</a> or type &#8220;perldoc perlreftut&#8221; if you have installed perldoc.</p>
<p>Well, just let do some sedish thinks :</p>
<blockquote><p>perl -ane &#8216;s/</p>
<p>]*)&gt;//; s/<br />
/<br />
/;print&#8217; file1.html</p></blockquote>
<p>replaces the paragraph in html( by newline () but keeps the options of the paragraph ($1, first match, here the parenthesis are not optional) in an html comment.</p>
<blockquote><p>perl -F&#8221;:&#8221; -ane &#8216;/pascal/ &amp;&amp; print $F[2]&#8216; /etc/passwd</p></blockquote>
<p>will print the UID of user pascal (third field), the field separator is &#8220;:&#8221; (-F$-1òý:òý)</p>
<blockquote><p>perl -ane &#8216;/$m[aiy][^ s]*/ &amp;&amp; print &#8220;line : $. variable : $&amp;n&#8221;&#8216;</p></blockquote>
<p>will print the number of line ($.) where the variables that begin with &#8220;$ma&#8221;, &#8220;$mi&#8221; o &#8220;$my&#8221; and the variables that have matched the description ($&amp;)</p>
<p>bad news, you received this bad MS file with carriage return (r) and newline and you want only the newline :</p>
<blockquote><p>perl -pi.old -ane &#8216;s/rn$/n/;print;&#8217; file1</p></blockquote>
<p>and I obtain directly a file1 without carriage return and I have a backup of the original in file1.old (-pi.old)<br />
you can have a look to a <a href="http://www.unixguide.net/unix/perl_oneliners.shtml" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.unixguide.net/unix/perl_oneliners.shtml?referer=');">quick look at some useful perl onliners</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2007/05/perl-on-the-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
