<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohit Arora on Medium]]></title>
        <description><![CDATA[Stories by Mohit Arora on Medium]]></description>
        <link>https://medium.com/@mohitsnp?source=rss-7f3c38b9e525------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WvmVebWRyvjhQ9M0.</url>
            <title>Stories by Mohit Arora on Medium</title>
            <link>https://medium.com/@mohitsnp?source=rss-7f3c38b9e525------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:55:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohitsnp/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AWK Magic !!!]]></title>
            <link>https://medium.com/@mohitsnp/awk-magic-da4cb814c958?source=rss-7f3c38b9e525------2</link>
            <guid isPermaLink="false">https://medium.com/p/da4cb814c958</guid>
            <category><![CDATA[awk]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[unix]]></category>
            <dc:creator><![CDATA[Mohit Arora]]></dc:creator>
            <pubDate>Thu, 27 Dec 2018 15:19:35 GMT</pubDate>
            <atom:updated>2018-12-27T15:23:59.838Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWK Magic !!!</h3><blockquote>If you are wondering what i am talking about. Please give a drum roll to the unix command AWK that is really powerful and I am going to show you why using an example. I am not being spender but once in a while like to calculate how much i am spending and on what.</blockquote><blockquote>So here is a snippet of my lavish lifestyle in csv (comma separated value) format.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*Ft_YCR3F-oyiPOpsp_lGHw.png" /></figure><blockquote>If you have guessed it as bank statement , you are right .</blockquote><blockquote>So now without further ado, lets dive in . As you can see there is some account info followed by transactions. We are only interested in later. How do we do it . <strong>We can summon AWK and ask for only lines that has as in this case 8 fields which form a transaction .</strong></blockquote><p><strong><em>awk ‘NF==8 {print}’ FS=, DATA3.csv</em></strong></p><blockquote>So awk has essentially two parts one for putting conditions on what to process and what operation. NF==8 means process only those rows which has eight fields. The operation is print itself . Plus you will have to tell awk what field separator is being used .FS=, takes care of it . And voila we have filtered transactions</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*PGbCppMfOncfRz7Nh8GyQQ.png" /></figure><blockquote>Now you may want to be picky and see only information like how much did my wife spend on groceries at her favorite Krish mini mart. AWK to the rescue again</blockquote><p><strong><em>awk ‘NF==8 &amp;&amp; /KRISH/ {print}’ FS=, DATA3.csv</em></strong></p><blockquote>You see what i did there I inserted a search pattern /KRISH/ that did the job for me.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*j3kC56anKrEOZgIKMw7PrQ.png" /></figure><blockquote>Now you must be pondering what if only i could calculate my groceries bill at KRISH. Well worry not .</blockquote><p><strong><em>awk ‘NF==8 &amp;&amp; /KRISH/ { tot += $3; print} END {print “TOTAL : “ tot}’ FS=, DATA3.csv</em></strong></p><p>Here we are adding the money spent from third field in a variable tot +=$3. And later using it to print the total expenses. Neat , isn’t it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*3s_mO8hsXk1J7lNIPhknog.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da4cb814c958" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>