<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Function on Amit Agarwal Linux Blog</title>
    <link>/tags/function/</link>
    <description>Recent content in Function on Amit Agarwal Linux Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Wed, 19 May 2010 16:38:47 +0000</lastBuildDate>
    
	<atom:link href="/tags/function/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Display the history and optionally grep</title>
      <link>/2010/05/19/display-the-history-and-optionally-grep/</link>
      <pubDate>Wed, 19 May 2010 16:38:47 +0000</pubDate>
      
      <guid>/2010/05/19/display-the-history-and-optionally-grep/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;Ever wondered how good it would be to have a command/function that would display the history or display the history with &amp;lt;a class=&amp;quot;zem_slink&amp;quot; title=&amp;quot;Grep&amp;quot; rel=&amp;quot;wikipedia&amp;quot; href=&amp;quot;http://en.wikipedia.org/wiki/Grep&amp;quot;&amp;gt;grep&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Would be really good right, well someone thought about this 🙂&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$ h() { if [ -z &amp;amp;#8221;$1&amp;amp;#8221; ]; then history; else history | grep &amp;amp;#8221;$@&amp;amp;#8221;; fi; }&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Place this in your .bash_profile and you can use it two different ways. If you issue &amp;amp;#8217;h&amp;amp;#8217; on its own, then it acts like the history command. If you issue:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Display a block of text with delineated by a start pattern and an end  pattern</title>
      <link>/2009/12/18/display-a-block-of-text-with-delineated-by-a-start-pattern-and-an-end-pattern/</link>
      <pubDate>Fri, 18 Dec 2009 07:43:41 +0000</pubDate>
      
      <guid>/2009/12/18/display-a-block-of-text-with-delineated-by-a-start-pattern-and-an-end-pattern/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;Taken idea from commandlinefu.com&lt;/p&gt;
&lt;p&gt;The command will display a segment from the file from the start pattern to the end pattern.&lt;/p&gt;
&lt;p&gt;function viewsegment() { tail -n +`fgrep -n -m 1 &amp;ldquo;$1&amp;rdquo; $3 | head -`fgrep -n -m 1 &amp;ldquo;$2&amp;rdquo; $3 }&lt;br&gt;
Display a block of text with delineated by a start pattern and an end pattern&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>View the newest xkcd comic.</title>
      <link>/2009/12/07/view-the-newest-xkcd-comic/</link>
      <pubDate>Mon, 07 Dec 2009 10:47:07 +0000</pubDate>
      
      <guid>/2009/12/07/view-the-newest-xkcd-comic/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;This function displays the latest comic from xkcd.com. One of the best things about xkcd is the title text when you hover over the comic, so this function also displays that after you close the comic.&lt;/p&gt;
&lt;p&gt;&lt;tt&gt;$ xkcd(){ local f=$(curl -s &amp;lt;a href=&amp;quot;http://xkcd.com/&amp;quot;&amp;gt;http://xkcd.com/&lt;/a&gt;);display $(echo &amp;quot;$f&amp;quot;|grep -Po &#39;(?&amp;lt;=&amp;quot;)http://imgs.xkcd.com/comics/[^&amp;quot;]+(png|jpg)&#39;);echo &amp;quot;$f&amp;quot;|awk &#39;/&amp;lt;img src=&amp;quot;http://imgs.xkcd.com/comics/.&lt;em&gt;?&amp;quot; title=.&lt;/em&gt;/{gsub(/^.&lt;em&gt;title=.|&amp;quot;.&lt;/em&gt;?$/,&amp;quot;&amp;quot;);print}&#39;;}&lt;/tt&gt;&lt;/p&gt;
&lt;p&gt;To get a random xkcd comic, I also use the following:&lt;/p&gt;
&lt;p&gt;&lt;tt&gt;xkcdrandom(){ local f=$(wget -q &amp;lt;a href=&amp;quot;http://dynamic.xkcd.com/comic/random/&amp;quot;&amp;gt;http://dynamic.xkcd.com/comic/random/&lt;/a&gt; -O -);display $(echo &amp;quot;$f&amp;quot;|grep -Po &#39;(?&amp;lt;=&amp;quot;)http://imgs.xkcd.com/comics/[^&amp;quot;]+(png|jpg)&#39;);echo &amp;quot;$f&amp;quot;|awk &#39;/&amp;lt;img src=&amp;quot;http://imgs.xkcd.com/comics/.&lt;em&gt;?&amp;quot; title=.&lt;/em&gt;/{gsub(/^.&lt;em&gt;title=.|&amp;quot;.&lt;/em&gt;?$/,&amp;quot;&amp;quot;);print}&#39;;}&lt;/tt&gt;&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>
