<?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>Wojciech Jamrozy blog &#187; commands</title>
	<atom:link href="http://www.wojtekrj.net/tag/commands/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wojtekrj.net</link>
	<description>Blog about computer science, programming and linux</description>
	<lastBuildDate>Sun, 23 Oct 2011 21:57:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[Bash] How to kill program after n seconds</title>
		<link>http://www.wojtekrj.net/2009/04/bash-how-to-kill-program-after-n-seconds/</link>
		<comments>http://www.wojtekrj.net/2009/04/bash-how-to-kill-program-after-n-seconds/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 17:11:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.wojtekrj.net/?p=152</guid>
		<description><![CDATA[I&#8217;m sorry that I haven&#8217;t written for such a long time. It&#8217;s going to change:) We have a program, which can suspend our terminal. We want to be sure, that program won&#8217;t be executed for more than n seconds. Here is a solution: &#40;&#40;sleep 10 &#38;&#38; killall top&#41;&#38;&#41;; top Explanation: sleep 10 is executed for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sorry that I haven&#8217;t written for such a long time. It&#8217;s going to change:)</p>
<p>We have a program, which can suspend our terminal. We want to be sure, that program won&#8217;t be executed for more than n seconds. Here is a solution:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">killall</span> top<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; top</pre></div></div>

<p>Explanation:<br />
<em>sleep 10 </em>is executed for 10 seconds and then exit (you can use <em>sleep n </em>if you want<em> sleep</em> to be executed for n seconds</p>
<p><em>killall top</em> terminates all processes named &#8220;top&#8221;</p>
<p><em>top </em>- is example of program; top shows information about processes in your system</p>
<p><em>command1 &amp;&amp; command2</em> &#8211; executes <em>command1</em> and then, if <em>command1</em> has succedeed, <em>command2</em></p>
<p><em>command</em> &amp; &#8211; executes <em>command</em> at the background of terminal</p>
<p><em>command1; command2</em> &#8211; executes <em>command1</em> and <em>command2</em>, even if<em> command1 hasn&#8217;t succedeed<br />
</em></p>
<p><a class="a2a_button_wykop" href="http://www.addtoany.com/add_to/wykop?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="Wykop" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/wykop.png" width="16" height="16" alt="Wykop"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="Digg" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_msdn" href="http://www.addtoany.com/add_to/msdn?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="MSDN" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/msdn.png" width="16" height="16" alt="MSDN"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_technotizie" href="http://www.addtoany.com/add_to/technotizie?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="Technotizie" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technotizie.png" width="16" height="16" alt="Technotizie"/></a><a class="a2a_button_technet" href="http://www.addtoany.com/add_to/technet?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;linkname=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" title="TechNet" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technet.png" width="16" height="16" alt="TechNet"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F04%2Fbash-how-to-kill-program-after-n-seconds%2F&amp;title=%5BBash%5D%20How%20to%20kill%20program%20after%20n%20seconds" id="wpa2a_2">Share/Save</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wojtekrj.net/2009/04/bash-how-to-kill-program-after-n-seconds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Bash] Text file manipulation</title>
		<link>http://www.wojtekrj.net/2008/08/bash-text-file-manipulation/</link>
		<comments>http://www.wojtekrj.net/2008/08/bash-text-file-manipulation/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 20:44:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[text file]]></category>

		<guid isPermaLink="false">http://www.wojtekrj.net/?p=84</guid>
		<description><![CDATA[I&#8217;m presenting here some text file manipulation commands with examples of usage. I want to enlarge on cat, tac, uniq, sort, head, tail, tr, wc and cut. Firstly, let&#8217;s create file named test.txt with following content: 1,AAAA,NNN 11,BBB,OOO 21,CCC,PPP 12,DDD,RRR 23,EEE,SSS 14,FFF,TTT 14,FFF,TTT 14,FFF,TTT 4,JJJJ,XXX 6,KKKK,YYY 5,LLLL,ZZZ 7,MMMM,AAA and test2.txt: 1000,aaa,bbb 1000,aaa,bbb Secondly, when you [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m presenting here some text file manipulation commands with examples of usage. I want to enlarge on <strong>cat</strong>, <strong>tac</strong>,<strong> uniq</strong>, <strong>sort</strong>, <strong>head</strong>, <strong>tail</strong>, <strong>tr</strong>, <strong>wc</strong> and <strong>cut</strong>.<span id="more-84"></span><br />
Firstly, let&#8217;s create file named test.txt with following content:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">7</span>,MMMM,AAA</pre></div></div>

<p>and test2.txt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">1000</span>,aaa,bbb
<span style="color: #000000;">1000</span>,aaa,bbb</pre></div></div>

<p>Secondly, when you write:<br />
<em>command1 | command2 | command 3</em> &#8211; the standard output of <em>command1</em> is the standard input of <em>command2</em> and the standard output of <em>command2</em> is the standard input of <em>command3</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;test&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cat</span>
<span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>

<p><em>command1 &amp;&amp; command2</em> &#8211; if <em>command1</em> is successfully executed, system will execute<em> command2</em></p>
<p><em>command1 &lt; infile &gt; outfile </em> &#8211; content of <em>infile</em> is standard input of<em> command1</em> and the output of <em>command1 </em>is saved to <em>outfile</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&lt;</span> test.txt <span style="color: #000000; font-weight: bold;">&gt;</span> test3.txt <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> test3.txt
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">7</span>,MMMM,AAA</pre></div></div>

<p>The file will be used to show working of commands:</p>
<p><strong>cat</strong> &#8211; without arguments it just copies standard input to standard output (if you use keyboard as standard input, type Ctrl+D when you finish &#8211; <strong>cat</strong> will treat it as EOF (end of file) character). If it has one argument, it will print content of file, which name is the first argument. If it has more arguments, it will print contents of files in order they apeared as arguments.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> test.txt
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">7</span>,MMMM,AAA
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> test2.txt
<span style="color: #000000;">1000</span>,aaa,bbb
<span style="color: #000000;">1000</span>,aaa,bbb
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> test.txt test2.txt
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">7</span>,MMMM,AAA
<span style="color: #000000;">1000</span>,aaa,bbb
<span style="color: #000000;">1000</span>,aaa,bbb</pre></div></div>

<p><strong>tac</strong> &#8211; it works like cat, but prints lines of files in reversed order</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">tac</span> test.txt
<span style="color: #000000;">7</span>,MMMM,AAA
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">1</span>,AAAA,NNN
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">tac</span> test.txt test2.txt
<span style="color: #000000;">7</span>,MMMM,AAA
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">1000</span>,aaa,bbb
<span style="color: #000000;">1000</span>,aaa,bbb</pre></div></div>

<p><strong>uniq</strong> &#8211; it prints content of file without subsequent same lines</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">uniq</span> test.txt
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">7</span>,MMMM,AAA
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">uniq</span> test2.txt
<span style="color: #000000;">1000</span>,aaa,bbb</pre></div></div>

<p><strong>sort</strong> &#8211; it sorts lines of file in lexicographical order. If command is executed with -n option, it will compare numbers at the begining of each line.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">sort</span> test.txt
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">7</span>,MMMM,AAA
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-n</span> test.txt
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">7</span>,MMMM,AAA
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">23</span>,EEE,SSS</pre></div></div>

<p><strong>nl </strong>- add a number before each line of file</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">nl</span>  test.txt
<span style="color: #000000;">1</span>	<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">2</span>	<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">3</span>	<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">4</span>	<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">5</span>	<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">6</span>	<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">7</span>	<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">8</span>	<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">9</span>	<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">10</span>	<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">11</span>	<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">12</span>	<span style="color: #000000;">7</span>,MMMM,AAA</pre></div></div>

<p><strong>head</strong> &#8211; prints first 10 lines of file. If it is executed with option -N, when N is a number, it will print first N lines of file</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">head</span> test.txt
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">6</span>,KKKK,YYY
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-3</span> test.txt
<span style="color: #000000;">1</span>,AAAA,NNN
<span style="color: #000000;">11</span>,BBB,OOO
<span style="color: #000000;">21</span>,CCC,PPP
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-1</span> test.txt
<span style="color: #000000;">1</span>,AAAA,NNN</pre></div></div>

<p><strong>tail</strong> &#8211; similar to head, but prints last lines</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">tail</span> test.txt
<span style="color: #000000;">21</span>,CCC,PPP
<span style="color: #000000;">12</span>,DDD,RRR
<span style="color: #000000;">23</span>,EEE,SSS
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">14</span>,FFF,TTT
<span style="color: #000000;">4</span>,JJJJ,XXX
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">7</span>,MMMM,AAA
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-3</span> test.txt
<span style="color: #000000;">6</span>,KKKK,YYY
<span style="color: #000000;">5</span>,LLLL,ZZZ
<span style="color: #000000;">7</span>,MMMM,AAA
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span> test.txt
<span style="color: #000000;">7</span>,MMMM,AAA</pre></div></div>

<p><strong>wc </strong>- it counts number of characters, words and lines of file. It can print statistics only for characters (option -c), words (-w) and lines (-l).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">wc</span> test.txt
<span style="color: #000000;">12</span>  <span style="color: #000000;">12</span> <span style="color: #000000;">132</span> test.txt
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-w</span> test.txt
<span style="color: #000000;">12</span> test.txt
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span> test.txt
<span style="color: #000000;">12</span> test.txt
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-c</span> test.txt
<span style="color: #000000;">132</span> test.txt</pre></div></div>

<p><strong>tr</strong> &#8211; read content from standard input and write to standard output deleting or changing some characters:<br />
<em>tr string1 string2</em> replaces first character from <em>string1 </em>to first character from <em>string2</em>, second to second, third to third, etc.<br />
<em>tr -d string1</em> deletes every occurrence of characters from<em> string1</em><br />
<em> tr -cd string1</em> deletes every occurence of characters, which are NOT from <em>string1</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> test2.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> abc ABC
<span style="color: #000000;">1000</span>,AAA,BBB
<span style="color: #000000;">1000</span>,AAA,BBB
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> test2.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #660033;">-d</span> abc
<span style="color: #000000;">1000</span>,,
<span style="color: #000000;">1000</span>,,
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> test2.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #660033;">-cd</span> abc
aaabbbaaabbb</pre></div></div>

<p><strong>cut </strong> &#8211; prints only part of line. Each line is constructed of fields separated by special character called separator.<br />
Let&#8217;s consider line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">1</span>,AAAA,NNN</pre></div></div>

<p>The separator is character &#8220;,&#8221;, there are 3 fields: first &#8211; &#8220;1&#8243;, second &#8211; &#8220;AAAA&#8221; and third &#8220;NNN&#8221;.<strong> cut</strong> has following syntax:<br />
<em>cut -d C -f N text.txt</em> where C is separator and N is number of field to display</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> , <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span>-<span style="color: #000000;">2</span> test.txt
<span style="color: #000000;">1</span>,AAAA
<span style="color: #000000;">11</span>,BBB
<span style="color: #000000;">21</span>,CCC
<span style="color: #000000;">12</span>,DDD
<span style="color: #000000;">23</span>,EEE
<span style="color: #000000;">14</span>,FFF
<span style="color: #000000;">14</span>,FFF
<span style="color: #000000;">14</span>,FFF
<span style="color: #000000;">4</span>,JJJJ
<span style="color: #000000;">6</span>,KKKK
<span style="color: #000000;">5</span>,LLLL
<span style="color: #000000;">7</span>,MMMM
wojtekrj<span style="color: #000000; font-weight: bold;">@</span>wojtek-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> , <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span>,<span style="color: #000000;">3</span> test.txt
<span style="color: #000000;">1</span>,NNN
<span style="color: #000000;">11</span>,OOO
<span style="color: #000000;">21</span>,PPP
<span style="color: #000000;">12</span>,RRR
<span style="color: #000000;">23</span>,SSS
<span style="color: #000000;">14</span>,TTT
<span style="color: #000000;">14</span>,TTT
<span style="color: #000000;">14</span>,TTT
<span style="color: #000000;">4</span>,XXX
<span style="color: #000000;">6</span>,YYY
<span style="color: #000000;">5</span>,ZZZ
<span style="color: #000000;">7</span>,AAA</pre></div></div>

<p>If you write after -f N-M fields from N to M will be printed. If N,M &#8211; N-th and M-th field will be printed.</p>
<p><a class="a2a_button_wykop" href="http://www.addtoany.com/add_to/wykop?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="Wykop" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/wykop.png" width="16" height="16" alt="Wykop"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="Digg" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_msdn" href="http://www.addtoany.com/add_to/msdn?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="MSDN" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/msdn.png" width="16" height="16" alt="MSDN"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_technotizie" href="http://www.addtoany.com/add_to/technotizie?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="Technotizie" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technotizie.png" width="16" height="16" alt="Technotizie"/></a><a class="a2a_button_technet" href="http://www.addtoany.com/add_to/technet?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;linkname=%5BBash%5D%20Text%20file%20manipulation" title="TechNet" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technet.png" width="16" height="16" alt="TechNet"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.wojtekrj.net%2F2008%2F08%2Fbash-text-file-manipulation%2F&amp;title=%5BBash%5D%20Text%20file%20manipulation" id="wpa2a_4">Share/Save</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wojtekrj.net/2008/08/bash-text-file-manipulation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

