<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8796493175195266816</id><updated>2023-04-06T21:24:48.259+05:30</updated><category term="Bash"/><category term="Awk"/><category term="bash shell newbie"/><category term="Linux Commands"/><category term="awk newbie"/><category term="bash shell"/><category term="Sed"/><category term="bash scripts"/><category term="Linux Utilities"/><category term="awk array"/><category term="ubuntu tips"/><category term="VIM"/><category term="vi editor tips"/><category term="awk if else"/><category term="Awk Functions"/><category term="bash tricks"/><category term="sed replacement"/><category term="find command"/><category term="vi handy commands"/><category term="awk for loop"/><category term="Bash Array"/><category term="bash parameter substitution"/><category term="awk variables"/><category term="bash for"/><category term="bash sort"/><category term="bash while"/><category term="linux paste"/><category term="python newbie"/><category term="Bash join"/><category term="awk FNR"/><category term="bash seq"/><category term="linux grep"/><category term="sed newbie"/><category term="xargs"/><category term="awk printf"/><category term="bc"/><category term="linux redirection"/><category term="linux tr"/><category term="SSH"/><category term="awk substr"/><category term="eval in awk"/><category term="unix epoch"/><category term="Bash if else"/><category term="Perl One liner"/><category term="awk replacement"/><category term="awk split"/><category term="bash loop"/><category term="command history"/><category term="exec"/><category term="linux cut"/><category term="linux diff"/><category term="Bash process substitution"/><category term="NW"/><category term="Solaris"/><category term="awk NR"/><category term="awk ORS"/><category term="awk groupby"/><category term="awk next"/><category term="awk patterns"/><category term="bash egrep command"/><category term="bash env variable"/><category term="bash function"/><category term="bash read"/><category term="bash until loop"/><category term="xml"/><category term="Awk strftime"/><category term="Bash Menu"/><category term="Bash Substring Removal"/><category term="CGI"/><category term="Expect"/><category term="Linux top"/><category term="UNIX look command"/><category term="UNIX rename"/><category term="UNIX screen"/><category term="UNIX time"/><category term="Unix less"/><category term="awk RS"/><category term="awk asort"/><category term="awk concatenation"/><category term="awk getline"/><category term="awk gsub"/><category term="awk report manipulation"/><category term="awk variable assignment"/><category term="bash and mysql"/><category term="bash command line argument"/><category term="bash desk calculator"/><category term="bash echo"/><category term="bash extglob"/><category term="bash printf"/><category term="bash scripts questions"/><category term="bash shopt"/><category term="bash truncate"/><category term="du command"/><category term="ftp"/><category term="getopts"/><category term="linux dd"/><category term="linux dialog"/><category term="linux ls"/><category term="linux sudo"/><category term="matrix operations using awk"/><category term="nohup"/><category term="operating system"/><category term="unix date"/><category term="vimdiff"/><category term="wcalc"/><title type='text'>UNIX Command Line</title><subtitle type='html'>&quot;Where there is a shell, there is a WAY !!&quot;&#xa;&#xa;Blog on Awk, Sed, BASH ones liners and scripts.&#xa; </subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.unixcl.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>425</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-1040722858259096193</id><published>2016-09-08T09:17:00.001+05:30</published><updated>2016-09-08T09:17:26.743+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu tips"/><title type='text'>Display ASCII pictures on Unix terminal</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&#39;cowsay&#39; is a program which generates ASCII pictures of a cow with a message.
&lt;br /&gt;
&lt;pre&gt;🐞  jsaikia@unixcl.com:~$ echo &quot;Hello World&quot; | cowsay
 _____________ 
&amp;lt; Hello World &amp;gt;
 ------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

&lt;/pre&gt;
You can change the &quot;Cow&quot; using the following option:
&lt;br /&gt;
&lt;pre&gt;                
🐞  jsaikia@unixcl.com:~$ echo &quot;Hello World&quot; | cowsay -f tux
 _____________ 
&amp;lt; Hello World &amp;gt;
 ------------- 
   \
    \
        .--.
       |o_o |
       |:_/ |
      //   \ \
     (|     | )
    /&#39;\_   _/`\
    \___)=(___/

🐞  jsaikia@unixcl.com:~$ echo &quot;Hello World&quot; | cowsay -f elephant
 _____________ 
&amp;lt; Hello World &amp;gt;
 ------------- 
 \     /\  ___  /\
  \   // \/   \/ \\
     ((    O O    ))
      \\ /     \ //
       \/  | |  \/ 
        |  | |  |  
        |  | |  |  
        |   o   |  
        | |   | |  
        |m|   |m| 

&lt;/pre&gt;
Available text characters are:
&lt;br /&gt;
&lt;pre&gt;🐞  jsaikia@unixcl.com:~$ cowsay -l
Cow files in /usr/local/Cellar/cowsay/3.04/share/cows:
beavis.zen blowfish bong bud-frogs bunny cheese cower daemon default dragon
dragon-and-cow elephant elephant-in-snake eyes flaming-sheep ghostbusters
head-in hellokitty kiss kitty koala kosh luke-koala meow milk moofasa moose
mutilated ren satanic sheep skeleton small sodomized stegosaurus stimpy
supermilker surgery telebears three-eyes turkey turtle tux udder vader
&lt;/pre&gt;
&lt;br /&gt;
&#39;fortune&#39; is yet another implementation of the Unix-style fortune program that displays a random message from a database of quotations. Something like:
&lt;br /&gt;
&lt;pre&gt;🐞  jsaikia@unixcl.com:~$ fortune
It is not every question that deserves an answer.
  -- Publilius Syrus
🐞  jsaikia@unixcl.com:~$ fortune
It is so soon that I am done for, I wonder what I was begun for.
  -- Epitaph, Cheltenham Churchyard

&lt;/pre&gt;
Now, you can make your cow quote the beautiful quotes from &#39;fortune&#39; and create something like the one I have (I have added this to my .bash_profile):&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://1.bp.blogspot.com/-enNl9fbzmsg/V9Dbyep91QI/AAAAAAAAN_I/DCd_dMB7CzkSRlIDqyjiG79gbAebkHZwQCLcB/s1600/Unix-ASCII-art-command-prompt-fortune-cowsay.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;226&quot; src=&quot;https://1.bp.blogspot.com/-enNl9fbzmsg/V9Dbyep91QI/AAAAAAAAN_I/DCd_dMB7CzkSRlIDqyjiG79gbAebkHZwQCLcB/s320/Unix-ASCII-art-command-prompt-fortune-cowsay.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can add the following to your .bash_profile or .bashrc to see a new cowsay fortune for every new terminal session:
&lt;pre&gt;fortune | cowsay
&lt;/pre&gt;
If you are on Mac OSX, you can get the cowsay and fortune installation details &lt;a href=&quot;https://gist.github.com/evnm/1308428#file-brew-install-missing-unix-tools&quot;&gt;here&lt;/a&gt;. If you need help in getting homebrew installed on your Mac OSX, here&#39;s the &lt;a href=&quot;https://coolestguidesontheplanet.com/installing-homebrew-on-os-x-el-capitan-10-11-package-manager-for-unix-apps/&quot;&gt;help&lt;/a&gt; link.
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/1040722858259096193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=1040722858259096193' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1040722858259096193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1040722858259096193'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2016/09/display-ascii-pictures-on-unix-terminal.html' title='Display ASCII pictures on Unix terminal'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://1.bp.blogspot.com/-enNl9fbzmsg/V9Dbyep91QI/AAAAAAAAN_I/DCd_dMB7CzkSRlIDqyjiG79gbAebkHZwQCLcB/s72-c/Unix-ASCII-art-command-prompt-fortune-cowsay.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-4451921818785912980</id><published>2016-01-01T07:58:00.002+05:30</published><updated>2016-01-01T07:58:49.950+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux Commands"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><title type='text'>Happy New Year 2016 in Unix way</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Wishing everyone a great 2016 ahead !&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://3.bp.blogspot.com/-BGg6e7V2ft0/VoXjTmtVuLI/AAAAAAAANlc/qFHuExIlaMs/s1600/Happy%2BNew%2BYear%2B2016%2B-%2BUnix.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;120&quot; src=&quot;http://3.bp.blogspot.com/-BGg6e7V2ft0/VoXjTmtVuLI/AAAAAAAANlc/qFHuExIlaMs/s640/Happy%2BNew%2BYear%2B2016%2B-%2BUnix.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&quot;toilet&quot; gives you color in UNIX terminal ! Read more &lt;a href=&quot;https://www.linux.com/learn/docs/686943-linux-tips-fun-with-figlet-and-toilet&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/4451921818785912980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=4451921818785912980' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4451921818785912980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4451921818785912980'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2016/01/happy-new-year-2016-in-unix-way.html' title='Happy New Year 2016 in Unix way'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-BGg6e7V2ft0/VoXjTmtVuLI/AAAAAAAANlc/qFHuExIlaMs/s72-c/Happy%2BNew%2BYear%2B2016%2B-%2BUnix.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-5005916042116667417</id><published>2015-11-25T13:04:00.000+05:30</published><updated>2015-11-25T13:04:29.984+05:30</updated><title type='text'>Display cricket score on Unix Terminal</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
If your job demands you to be on Unix console all the time and you happen to be one who can not avoid watching the cricket score, something you would like:&lt;br /&gt;
The script:
&lt;br /&gt;
&lt;pre&gt;#!/bin/sh
#Get cricket score on your unix console top corner, enjoy cricket while you work ..

columns=$(tput cols)
startpoint=$(($columns-100))
matchurl=&#39;http://www.espncricinfo.com/india-v-south-africa-2015-16/engine/match/903607.html&#39;

while :
do
  line=$(wget -q -O- $matchurl  | awk -F &#39;=&#39; &#39;/og:title/ {print $3}&#39; | awk -F &#39;|&#39; &#39;{print $1}&#39; | sed &#39;s/&quot;//g&#39;)
  echo -en &quot;\033[s&quot;    #save current screen position &amp;amp; attributes
  tput cup 0 $startpoint
  echo -en &quot;\033[42m$line\033[0m&quot;
  echo -e -n &quot;\033[u&quot;
  sleep 15
done
&lt;/pre&gt;
Output:
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://2.bp.blogspot.com/-Jg22qneH9gY/VlVj6mtvBNI/AAAAAAAANj8/i3Mz5UCPn3Y/s1600/Unix-Cricket-score-update-script.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-Jg22qneH9gY/VlVj6mtvBNI/AAAAAAAANj8/i3Mz5UCPn3Y/s320/Unix-Cricket-score-update-script.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/5005916042116667417/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=5005916042116667417' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/5005916042116667417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/5005916042116667417'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2015/11/display-cricket-score-on-unix-terminal.html' title='Display cricket score on Unix Terminal'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-Jg22qneH9gY/VlVj6mtvBNI/AAAAAAAANj8/i3Mz5UCPn3Y/s72-c/Unix-Cricket-score-update-script.png" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-1915536510968126100</id><published>2015-11-06T16:03:00.003+05:30</published><updated>2015-11-06T16:03:22.829+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><title type='text'>Bash - Get function name inside a function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
$FUNCNAME has the function name in a bash script which can be used for useful purpose like the following:

Script:test.sh
&lt;pre&gt;
!/bin/sh

WORKID=$(date +%s) ; mkdir $WORKID
LOGFILE=$WORKID/$(basename $0).log

_f_log() {
        echo &quot;$(date):$@&quot; &gt;&gt; $LOGFILE
}

_f_testFunc() {
        local logfile=$1
        local status=$2
        _f_log &quot;$FUNCNAME:$logfile:$status&quot;

}

_f_testFunc /tmp/a.log restart
&lt;/pre&gt;
Executing it:
&lt;pre&gt;
$ ./test.sh
&lt;/pre&gt;
Result:
&lt;pre&gt;
$ cat 1446805714/test.sh.log
Fri Nov  6 15:58:34 IST 2015:_f_testFunc:/tmp/a.log:restart
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/1915536510968126100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=1915536510968126100' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1915536510968126100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1915536510968126100'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2015/11/bash-get-function-name-inside-function.html' title='Bash - Get function name inside a function'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-585377228506639511</id><published>2015-03-07T21:58:00.000+05:30</published><updated>2015-03-07T21:58:10.826+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><category scheme="http://www.blogger.com/atom/ns#" term="xargs"/><title type='text'>Unix - run multiple commands on remote machines in parallel</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Assume you have a requirement of running two commands on 10 hosts.&lt;br /&gt;
&lt;br /&gt;
In this post I would like to show you how you can:&lt;br /&gt;
&lt;br /&gt;
1) Run multiple commands on remote host using ssh.&lt;br /&gt;
&lt;br /&gt;
2) Also instead of working on one host at a time serially, how can we execute the commands on multiple hosts in parallel to save the overall execution time.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Example:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
Find the number of files under &#39;/sdb/_read/&#39; and &#39;/sdb/_write/&#39; directories on following 10 hosts. 
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat host.txt 
192.19.66.203
192.19.66.204
192.19.66.205
192.19.66.206
192.19.66.207
192.19.66.208
192.19.66.209
192.19.66.210
192.19.66.211
192.19.66.212
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Serial execution:&amp;nbsp;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
We can write a bash for loop and work on each host like this:
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; for ip in $(cat host.txt); do echo -n &quot;$ip|&quot;; ssh -2 root@$ip &#39;R=$(ls /sdb/_read/ | wc -l ) ; D=$(ls /sdb/_write/ | wc -l) ; echo &quot;$R|$D&quot;&#39;; done
&lt;/pre&gt;
&lt;br /&gt;
Time taken:
&lt;br /&gt;
&lt;pre&gt;real 0m50.084s
user 0m0.052s
sys 0m0.032s
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Parallel execution:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
I have already blogged about Unix xargs parallel execution option &lt;a href=&quot;http://www.unixcl.com/2014/04/unix-xargs-parallel-execution-of.html&quot;&gt;here&lt;/a&gt;, using that:
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat host.txt  | xargs -n 1 -P 5 -i ssh -2 root@{} &#39;I=$(hostname -i);R=$(ls /sdb/_read/ | wc -l ) ; D=$(ls /sdb/_write/ | wc -l)  ; echo &quot;$I|$R|$D&quot;&#39;
&lt;/pre&gt;
&lt;br /&gt;
Time taken:
&lt;br /&gt;
&lt;pre&gt;real 0m10.437s
user 0m0.044s
sys 0m0.036s
&lt;/pre&gt;
&lt;br /&gt;
10 Seconds vs 50 Seconds, wow !&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;pre&gt;192.19.66.205|0|4
192.19.66.204|0|0
192.19.66.203|0|0
192.19.66.207|5|0
192.19.66.206|0|0
192.19.66.208|0|0
192.19.66.209|0|7
192.19.66.210|0|0
192.19.66.211|2|1
192.19.66.212|9|0
&lt;/pre&gt;
&lt;br /&gt;
Note: Utilities like&amp;nbsp;&lt;a href=&quot;http://www.gnu.org/software/parallel/&quot;&gt;GNU parallel&lt;/a&gt;&amp;nbsp;or &lt;a href=&quot;https://code.google.com/p/parallel-ssh/&quot;&gt;Parallel SSH&lt;/a&gt;&amp;nbsp;are always the best tool in this job.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Related posts:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2014/04/unix-xargs-parallel-execution-of.html&quot;&gt;Unix Xargs paralel execution&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2014/12/execute-script-on-remote-server-ssh-unix.html&quot;&gt;Unix - Execute script on remote host using SSH without copying the script.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2009/01/diff-remote-files-using-ssh-in-linux.html&quot;&gt;Diff remote files using SSH in Unix&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2008/01/using-ssh-from-bash.html&quot;&gt;Bash and SSH some examples&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/585377228506639511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=585377228506639511' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/585377228506639511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/585377228506639511'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2015/03/unix-run-multiple-commands-on-remote.html' title='Unix - run multiple commands on remote machines in parallel'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-1317916935908095926</id><published>2015-01-01T00:21:00.001+05:30</published><updated>2015-01-01T00:21:19.977+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><title type='text'>Happy new year 2015 to all unix lovers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
Wishing all the readers of unixcl.com a Happy and Healthy 2015 ahead, keep rocking !&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://4.bp.blogspot.com/-YFjDu2IrJc8/VKRFJ7-eTgI/AAAAAAAAMKg/bv5ur3Z29rE/s1600/Happy%2BNew%2BYear%2B2015.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-YFjDu2IrJc8/VKRFJ7-eTgI/AAAAAAAAMKg/bv5ur3Z29rE/s1600/Happy%2BNew%2BYear%2B2015.png&quot; height=&quot;361&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/1317916935908095926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=1317916935908095926' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1317916935908095926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1317916935908095926'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2015/01/happy-new-year-2015-to-all-unix-lovers.html' title='Happy new year 2015 to all unix lovers'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-YFjDu2IrJc8/VKRFJ7-eTgI/AAAAAAAAMKg/bv5ur3Z29rE/s72-c/Happy%2BNew%2BYear%2B2015.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-4270189125938400886</id><published>2014-12-20T17:44:00.002+05:30</published><updated>2014-12-20T17:44:58.073+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="linux grep"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><category scheme="http://www.blogger.com/atom/ns#" term="Sed"/><category scheme="http://www.blogger.com/atom/ns#" term="sed newbie"/><title type='text'>Unix - Delete blank lines from file</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here&#39;s some ways to remove empty or blank lines from a file in Unix. Simple but definitely useful.
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; grep -v &#39;^$&#39; file.txt
&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; grep &#39;.&#39; file.txt
&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; sed &#39;/^$/d&#39; file.txt
&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; sed -n &#39;/^$/!p&#39; file.txt
&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk NF file.txt
&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;/./&#39; file.txt
&lt;/pre&gt;
&lt;br /&gt;
In Vi editor, in escape mode type
&lt;br /&gt;
&lt;pre&gt;:g/^$/ d
&lt;/pre&gt;
Related posts:

&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2008/12/remove-duplicate-blank-lines-bash-awk.html&quot;&gt;Unix - Remove duplicate blank lines from file using Awk&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2009/12/awk-numbering-lines-ignoring-blank.html&quot;&gt;Unix - Numbering lines of a file ignoring blank lines using Awk&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/4270189125938400886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=4270189125938400886' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4270189125938400886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4270189125938400886'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2014/12/unix-delete-blank-lines-from-file.html' title='Unix - Delete blank lines from file'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-4373725759603005267</id><published>2014-12-13T13:49:00.000+05:30</published><updated>2014-12-13T13:49:21.830+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><category scheme="http://www.blogger.com/atom/ns#" term="SSH"/><title type='text'>Execute script on remote server SSH - Unix</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Assume you have a complex bash script named &#39;run_q.sh&#39; (containing good number of loops, Awk statements, multiple lines of code etc) that you need to run against one or more remote servers via SSH.

One way would be to copy (i.e. scp) the script to the remote server(s) and then do something like this:

e.g.
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; scp -2 run_q.sh root@192.168.32.8:/tmp/.

&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; ssh -2 root@192.168.32.8 sh /tmp/run_q.sh
&lt;/pre&gt;
If its multiple machines, then you can use bash for loop like this:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; for ip in 192.168.32.8 192.168.32.9 192.168.32.3 ; do echo &quot;Executing on IP: $ip&quot; ; ssh -2 root@$ip &#39;sh /tmp/run_q.sh&#39; ; done
&lt;/pre&gt;
Now assume you do not want to copy your script to the remote machine(s) and want to execute from your local machine without copying it. 

Here&#39;s a way:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat run_q.sh | ssh -2 root@192.168.32.8 /bin/sh
&lt;/pre&gt;
And if its to be executed on multiple machines, you can use a for loop like this:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; for ip in 192.168.32.8 192.168.32.9 192.168.32.3 ; do echo &quot;Executing on IP: $ip&quot; ; cat run_q.sh | ssh -2 root@$ip /bin/sh ; done
&lt;/pre&gt;
I am sure you liked this trick ! Feel free to comment below. Thanks.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Related posts:
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2009/01/diff-remote-files-using-ssh-in-linux.html&quot;&gt;Diff remote files using SSH in Unix&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/4373725759603005267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=4373725759603005267' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4373725759603005267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4373725759603005267'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2014/12/execute-script-on-remote-server-ssh-unix.html' title='Execute script on remote server SSH - Unix'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-1834203730312574960</id><published>2014-04-27T09:11:00.002+05:30</published><updated>2014-04-27T09:11:49.558+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="xargs"/><title type='text'>Unix xargs parallel execution of commands</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Xargs has option that allows you to take advantage of multiple cores in your machine. 
Its -P option which allows xargs to invoke the specified command multiple times in parallel. 


From XARGS(1) man page:
&lt;br /&gt;
&lt;pre&gt;-P max-procs
   Run up to max-procs processes at a time; the default is 1.  If max-procs is 0, xargs will run as many processes as possible at a time.   Use  the  -n  option
   with -P; otherwise chances are that only one exec will be done.

-n max-args
    Use at most max-args arguments per command line.  Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the  -x  
    option is given, in which case xargs will exit.

-i[replace-str]
    This option is a synonym for -Ireplace-str if replace-str is specified, and for -I{} otherwise.  This option is deprecated; use -I instead.
&lt;/pre&gt;
Let me try to give one example where we can make use of this parallel option avaiable on xargs.
e.g. I got these 8 log files (each one is of 1.5G size) for which I have to run a script named count_pipeline.sh which does some calculation around the log lines in the log file.
&lt;br /&gt;
&lt;pre&gt;$ ls -1 *.out
log1.out
log2.out
log3.out
log4.out
log5.out
log6.out
log7.out
log8.out
&lt;/pre&gt;
The script count_pipeline.sh takes nearly 20 seconds for a single log file. e.g.
&lt;br /&gt;
&lt;pre&gt;$ time ./count_pipeline.sh log1.out

real 0m20.509s
user 0m20.967s
sys 0m0.467s
&lt;/pre&gt;
If we have to run count_pipeline.sh for each of the 8 log files one after the other, total time needed:
&lt;br /&gt;
&lt;pre&gt;$ time ls *.out | xargs -i ./count_pipeline.sh {}           

real 2m45.862s
user 2m48.152s
sys 0m5.358s
&lt;/pre&gt;
Running with 4 parallel processes at a time (I am having a machine which is having 4 CPU cores):
&lt;br /&gt;
&lt;pre&gt;$ time ls *.out | xargs -i -P4 ./count_pipeline.sh {} 

real 0m44.764s
user 2m55.020s
sys 0m6.224s
&lt;/pre&gt;
We saved time ! Isn&#39;t this useful ? 

You can also use -n1 option instead of the -i option that I am using above. 

-n1 passes one arg a time to the run comamnd (instead of the xargs default of passing all args).
&lt;br /&gt;
&lt;pre&gt;$ time ls *.out | xargs -n1 -P4 ./count_pipeline.sh

real 0m43.229s
user 2m56.718s
sys 0m6.353s
&lt;/pre&gt;
&lt;br /&gt;
Related posts:&lt;br /&gt;
- &lt;a href=&quot;http://www.unixcl.com/2010/08/unix-handle-kill-when-no-pid.html&quot;&gt;UNIX handle kill when no PID available&lt;/a&gt;&amp;nbsp;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/1834203730312574960/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=1834203730312574960' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1834203730312574960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1834203730312574960'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2014/04/unix-xargs-parallel-execution-of.html' title='Unix xargs parallel execution of commands'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-3899793044999671397</id><published>2013-07-26T09:34:00.004+05:30</published><updated>2013-07-26T09:34:39.493+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="linux paste"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><title type='text'>Unix - merge multiple consecutive lines</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Input file:&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat infile.txt 
aid=33
pw=3
nn=90
aid=32
pw=30
nn=70
aid=56
pw=3
nn=93
&lt;/pre&gt;
Required:&lt;br /&gt;
Combine or merge every three consecutive lines of the above file so that the output becomes:
&lt;br /&gt;
&lt;pre&gt;aid=33,pw=3,nn=90
aid=32,pw=30,nn=70
aid=56,pw=3,nn=93
&lt;/pre&gt;
Awk solution: If line number is divisible by 3 then put a new line(\n) else put a comma(,) i.e.
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;{printf(&quot;%s%s&quot;, $0, (NR%3 ? &quot;,&quot; : &quot;\n&quot;))}&#39; infile.txt 
aid=33,pw=3,nn=90
aid=32,pw=30,nn=70
aid=56,pw=3,nn=93
&lt;/pre&gt;
Another way using Awk:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;NR%3{printf $0&quot;,&quot;;next;}1&#39; infile.txt 
aid=33,pw=3,nn=90
aid=32,pw=30,nn=70
aid=56,pw=3,nn=93
&lt;/pre&gt;
Using UNIX paste command:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; paste -d&quot;,&quot; - - - &amp;lt; infile.txt 
aid=33,pw=3,nn=90
aid=32,pw=30,nn=70
aid=56,pw=3,nn=93
&lt;/pre&gt;
A bash command line solution:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; while read line1; do read line2; read line3; echo &quot;$line1,$line2,$line3&quot;; done &amp;lt; infile.txt 
aid=33,pw=3,nn=90
aid=32,pw=30,nn=70
aid=56,pw=3,nn=93
&lt;/pre&gt;
Related posts:&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2008/04/join-multiple-lines-using-awk.html&quot;&gt;Join multiple lines using Awk&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2009/05/combine-related-consecutive-lines-awk.html&quot;&gt;Combine related consecutive lines using Awk&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.unixcl.com/2008/07/merging-lines-using-awk-bash.html&quot;&gt;Merging lines in UNIX&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/3899793044999671397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=3899793044999671397' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3899793044999671397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3899793044999671397'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2013/07/unix-merge-multiple-consecutive-lines.html' title='Unix - merge multiple consecutive lines'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-8183031634177536371</id><published>2013-05-08T10:33:00.004+05:30</published><updated>2013-05-08T10:33:40.513+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk if else"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><title type='text'>Unix - Append 0 to single digit date</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Input file file.txt has dates in month/day/year format. 
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat file.txt 
3/4/2013
3/10/2013
10/4/2013
12/10/2012
&lt;/pre&gt;
Required: Add prefix 0 to first and second field if its a single digit. &lt;br /&gt;
&lt;br /&gt;
Awk solution:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;BEGIN {FS=OFS=&quot;/&quot;} 
    { 
 if (length($1) == 1) $1=&quot;0&quot;$1
 if (length($2) == 1) $2=&quot;0&quot;$2
        { print }
}&#39; file.txt
&lt;/pre&gt;
Output:
&lt;br /&gt;
&lt;pre&gt;03/04/2013
03/10/2013
10/04/2013
12/10/2012
&lt;/pre&gt;
Related posts: &lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2010/11/newbie-tutorial-on-unix-awk-utility.html&quot;&gt;A newbie tutorial on Unix Awk&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/09/if-else-examples-in-awk-bash.html&quot;&gt;Awk if else&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/07/convert-date-format-using-sed-awk-perl.html&quot;&gt;Convert date format in unix using awk and sed&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/8183031634177536371/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=8183031634177536371' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/8183031634177536371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/8183031634177536371'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2013/05/unix-append-0-to-single-digit-date.html' title='Unix - Append 0 to single digit date'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-5118065520929847874</id><published>2013-02-28T08:54:00.000+05:30</published><updated>2013-02-28T08:54:02.816+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Commands"/><category scheme="http://www.blogger.com/atom/ns#" term="linux redirection"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><category scheme="http://www.blogger.com/atom/ns#" term="UNIX time"/><title type='text'>UNIX time command output redirect to file</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
As you know the &#39;time&#39; command run programs and summarize system resource usage. Here is a way how you can redirect &#39;time&#39; command output to file. I would recomend you to go through &lt;a href=&quot;http://www.trentu.ca/academic/physics/batkinson/scalapack_docs/node18.html&quot;&gt;this page&lt;/a&gt; to understand more about &#39;time&#39; command.&lt;br /&gt;
&lt;br /&gt;
e.g. We are executing &#39;prog.sh&#39; along with &#39;time&#39; command.
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; time ./prog.sh 
Initiating merge
Merge completed

real	0m8.803s
user	0m0.010s
sys	0m0.000s
&lt;/pre&gt;
#Trying to redirect the output to a file
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; time ./prog.sh &amp;gt; out.txt

real	0m8.804s
user	0m0.020s
sys	0m0.000s
&lt;/pre&gt;
#out.txt content:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat out.txt 
Initiating merge
Merge completed
&lt;/pre&gt;
#So it only redirected the STDOUT of the script executed, but the &#39;time&#39; command outut is not redirected. &lt;br /&gt;
#This is becuase the command time sends it&#39;s output to STDERR (instead of STDOUT)&lt;br /&gt;
#To capture output of &#39;time&#39; command:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; { time ./prog.sh ; } 2&amp;gt; out.txt
Initiating merge
Merge completed
&lt;/pre&gt;
#Now out.txt content:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat out.txt 

real	0m8.303s
user	0m0.010s
sys	0m0.000s
&lt;/pre&gt;
#And to capture output of script as well as time command:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; { time ./prog.sh ; } &amp;amp;&amp;gt; out.txt
&lt;/pre&gt;
#&#39;out.txt&#39; now has both the outputs.
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat out.txt 
Initiating merge
Merge completed

real	0m8.303s
user	0m0.020s
sys	0m0.000s
&lt;/pre&gt;
As I have mentioned in my earlier &lt;a href=&quot;http://unstableme.blogspot.in/2008/03/understand-your-codes-performance-using.html&quot;&gt;post&lt;/a&gt; on UNIX &#39;time&#39; command, there&#39;s two types of time command available:&lt;br /&gt;
1) Shell&#39;s in-build time: Gives only scheduler information&lt;br /&gt;
2) /usr/bin/time: Gives more information, also allows formatting the output&lt;br /&gt;
&lt;br /&gt;
The second (/usr/bin/time) one accepts output redirection without code block:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; /usr/bin/time ./prog.sh &amp;amp;&amp;gt; newout.txt

&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat newout.txt 
Initiating merge
Merge completed
0.00user 0.01system 0:08.30elapsed 0%CPU (0avgtext+0avgdata 5728maxresident)k
0inputs+8outputs (0major+719minor)pagefaults 0swaps
&lt;/pre&gt;
Related posts:&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/01/redirecting-man-pages-to-file-linux.html&quot;&gt;UNIX redirect man pages to file&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/12/redirect-top-command-output-to-file.html&quot;&gt;Redirect UNIX top command output to file&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/08/redirect-both-stderr-and-stdout-to.html&quot;&gt;UNIX redirect both stderr and stdout to file&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2012/02/run-unix-bash-loop-with-nohup.html&quot;&gt;Run UNIX bash loop with nohup command&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/5118065520929847874/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=5118065520929847874' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/5118065520929847874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/5118065520929847874'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2013/02/unix-time-command-output-redirect-to.html' title='UNIX time command output redirect to file'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-4623789452762498863</id><published>2013-02-15T22:27:00.003+05:30</published><updated>2013-02-15T22:28:43.509+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash command line argument"/><category scheme="http://www.blogger.com/atom/ns#" term="bash function"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="bash while"/><category scheme="http://www.blogger.com/atom/ns#" term="getopts"/><category scheme="http://www.blogger.com/atom/ns#" term="Sed"/><category scheme="http://www.blogger.com/atom/ns#" term="sed newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="sed replacement"/><title type='text'>Bash - convert delimited file to html table</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is a simple UNIX bash script that can be used to convert a simple delimited file to a HTML table format. Default delimiter if not mentioned as part of the command line argument to this script will be comma. 

&lt;br /&gt;
&lt;pre&gt;#!/bin/sh
#convert_2_html_table.sh 
#Converts a delimited file to a HTML table
#Jadu Saikia http://unstableme.blogspot.in

NOARG=64

#usage function
f_Usage () {
echo &quot;Usage: $(basename $0) -d &amp;lt;delimiter&amp;gt; -f &amp;lt;delimited-file&amp;gt;&quot;
}

#command line args
while getopts d:f: OPTION
do
    case $OPTION in
        d)  DELIMITER=$OPTARG ;;
        f)  INFILE=$OPTARG ;;
    esac
done

#Less than 2 command line argument, throw Usage
[ &quot;$#&quot; -lt 2 ] &amp;amp;&amp;amp; f_Usage &amp;amp;&amp;amp; exit $NOARG

DEFAULTDELIMITER=&quot;,&quot;
#If no delimiter is supplied, default delimiter is comma i.e. ,
SEPARATOR=${DELIMITER:-$DEFAULTDELIMITER}

if [ -f &quot;${INFILE}&quot; ]
        then
                printf &quot;&amp;lt;table border=\&quot;1\&quot;&amp;gt;&quot;
                sed &quot;s/$SEPARATOR/&amp;lt;\/td&amp;gt;&amp;lt;td&amp;gt;/g&quot; $INFILE | while read line
                        do
                                printf &quot;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;${line}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&quot;
                done
                printf &quot;&amp;lt;/table&amp;gt;&quot;
                echo
fi

&lt;/pre&gt;
e.g. Input file:
&lt;br /&gt;
&lt;pre&gt;$ cat data.txt 
First Name:Last Name:Points
Alex:Hall:45
Niraj:Kumar:290
Brian:Smith:100
&lt;/pre&gt;
Executing it:
&lt;br /&gt;
&lt;pre&gt;$ ./convert_2_html_table.sh -d &quot;:&quot; -f data.txt  &amp;gt; data.html
&lt;/pre&gt;
&lt;a href=&quot;http://1.bp.blogspot.com/-r7PsGwwuMWM/UR5n2JMMGHI/AAAAAAAAFSc/-atCvP2OGM4/s1600/Unix-Bash-convert-delimited-file-to-html-table.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-r7PsGwwuMWM/UR5n2JMMGHI/AAAAAAAAFSc/-atCvP2OGM4/s320/Unix-Bash-convert-delimited-file-to-html-table.png&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&amp;nbsp;Related posts:&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2007/12/setting-default-value-for-shell.html&quot;&gt;Setting default value for Bash shell variable&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/03/accessing-external-variable-in-awk-and.html&quot;&gt;Accessing external variable in SED and AWK&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/10/bash-while-loop-sum-issue-explained.html&quot;&gt;Issue with Bash while loop during SUM&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/4623789452762498863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=4623789452762498863' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4623789452762498863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4623789452762498863'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2013/02/bash-convert-delimited-file-to-html.html' title='Bash - convert delimited file to html table'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-r7PsGwwuMWM/UR5n2JMMGHI/AAAAAAAAFSc/-atCvP2OGM4/s72-c/Unix-Bash-convert-delimited-file-to-html-table.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-2496397111758386033</id><published>2012-11-25T23:03:00.002+05:30</published><updated>2012-11-25T23:03:33.589+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Commands"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><category scheme="http://www.blogger.com/atom/ns#" term="UNIX screen"/><title type='text'>Beginning of line in UNIX screen session</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
As you know every &quot;screen&quot; command begins with &quot;Ctrl-a&quot;, then how to go to beginning of the line when you are working under a &quot;screen&quot; UNIX session (which we achieve by &quot;Ctrl-a&quot; in a normal UNIX session) ? &lt;br /&gt;&lt;br /&gt;Solution:&lt;br /&gt;Under a &quot;screen&quot; UNIX session you can do &quot;Ctrl-a a&quot; to move to the beginning of the line. &lt;br /&gt;&lt;br /&gt;So in order to print ^A (hex: \x01) in a UNIX &quot;screen&quot; session, usual&amp;nbsp; &quot;Ctrl-v Ctrl-a&quot; will not work, you will type &quot;Ctrl-v Ctrl-a a&quot; to print ^A.&lt;br /&gt;
&lt;br /&gt;
Related posts:&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/08/bash-save-command-without-executing-it.html&quot;&gt;Save command without executing it in Bash history&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/04/ctrl-s-in-linux-shell-vi-hangs.html&quot;&gt;Ctrl s freezes UNIX shell and vi editor&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2010/01/prevent-exit-of-shell-with-ctrl-d.html&quot;&gt;UNIX - prevent exit of shell with Ctrl-d&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/01/linux-command-line-history-with.html&quot;&gt;Print UNIX command line history with time-stamp of command execution &lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/2496397111758386033/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=2496397111758386033' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/2496397111758386033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/2496397111758386033'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/11/beginning-of-line-in-unix-screen-session.html' title='Beginning of line in UNIX screen session'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-4455746666953596743</id><published>2012-11-21T08:24:00.001+05:30</published><updated>2012-11-21T08:25:42.465+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="bash for"/><category scheme="http://www.blogger.com/atom/ns#" term="bash seq"/><category scheme="http://www.blogger.com/atom/ns#" term="linux paste"/><title type='text'>Transpose using UNIX paste command</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I have already posted about performing transpose of a matrix using Awk in my earlier posts &lt;a href=&quot;http://unstableme.blogspot.in/2008/05/transpose-using-awk-bash.html&quot;&gt;post1&lt;/a&gt; and &lt;a href=&quot;http://unstableme.blogspot.in/2008/08/row-to-column-transpose-bash-scripting.html&quot;&gt;post2&lt;/a&gt; . This example shows a not so efficient way of achieving the same. &lt;br/&gt;
&lt;br/&gt;Input file:
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat file.txt 
 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                                                      
32420 testuser 20   0 1219m 969m  49m R   34 12.1   1043:14 worker
&lt;/pre&gt;
Required output:
&lt;br /&gt;
&lt;pre&gt;PID 32420
USER testuser
PR 20
NI 0
VIRT 1219m
RES 969m
SHR 49m
S R
%CPU 34
%MEM 12.1
TIME+ 1043:14
COMMAND worker
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; for i in $(seq 12); do awk -v X=$i &#39;{print $X}&#39; file.txt | paste - - ; done
&lt;/pre&gt;
Related posts:&lt;br/&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/03/accessing-external-variable-in-awk-and.html&quot;&gt;How to access external variable in Awk and SED&lt;/a&gt;&lt;br/&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2007/02/generating-loop-arguments-seq-command.html&quot;&gt;Generate bash loop arguments using seq command&lt;/a&gt;&lt;br/&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/09/linux-seq-command-format-option-example.html&quot;&gt;UNIX seq command format option example&lt;/a&gt;&lt;br/&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/01/linux-paste-command-good-examples-uses.html&quot;&gt;Some good usage of UNIX paste command&lt;/a&gt;&lt;br/&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2012/09/compare-two-numeric-fields-of-two-files.html&quot;&gt;Compare two numeric fields of two files in Bash&lt;/a&gt;&lt;br/&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/4455746666953596743/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=4455746666953596743' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4455746666953596743'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/4455746666953596743'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/11/transpose-using-unix-paste-command.html' title='Transpose using UNIX paste command'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-8200153849104201230</id><published>2012-11-14T22:18:00.000+05:30</published><updated>2012-11-14T22:25:10.572+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="UNIX rename"/><title type='text'>UNIX - append text to filename using Awk</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I have some files in my current directory whose file-name is of this pattern:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; ls -1
log.1024.94.1326776200.1326776300.172.16.12.6.1326844995.0.s-1326528000.r-8192.txt
log.1024.94.1326776400.1326776400.172.16.12.5.1326844995.0.s-1326528000.r-2234.txt
log.1024.95.1326776420.1326776460.172.16.12.5.1326844995.0.s-1326528000.r-8192.txt
&lt;/pre&gt;
Requirement: Append a text &quot;MY-2&quot; as the 6th field (dot delimited) of the filename. E.g.
&lt;br /&gt;
&lt;pre&gt; 
log.1024.94.1326776200.1326776300.172.16.12.6.1326844995.0.s-1326528000.r-8192.txt 
&lt;/pre&gt;
should be renamed to
&lt;br /&gt;
&lt;pre&gt;log.1024.94.1326776200.1326776300.&lt;span style=&quot;color: blue;&quot;&gt;MY-2&lt;/span&gt;.172.16.12.6.1326844995.0.s-1326528000.r-8192.txt
&lt;/pre&gt;
A bash script using awk to achieve this:
&lt;br /&gt;
&lt;pre&gt;for file in $(ls)
 do 
  newfilename=$(echo $file | awk &#39;BEGIN {FS=OFS=&quot;.&quot;} {$6=&quot;MY-2&quot; OFS $6} {print}&#39;)
  mv -v $file $newfilename
done
&lt;/pre&gt;
All the files are renamed to:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; ls -1
log.1024.94.1326776200.1326776300.&lt;span style=&quot;color: blue;&quot;&gt;MY-2&lt;/span&gt;.172.16.12.6.1326844995.0.s-1326528000.r-8192.txt
log.1024.94.1326776400.1326776400.&lt;span style=&quot;color: blue;&quot;&gt;MY-2&lt;/span&gt;.172.16.12.5.1326844995.0.s-1326528000.r-2234.txt
log.1024.95.1326776420.1326776460.&lt;span style=&quot;color: blue;&quot;&gt;MY-2&lt;/span&gt;.172.16.12.5.1326844995.0.s-1326528000.r-8192.txt
&lt;/pre&gt;
Feel free to post (as comment below) any alternative to this, much appreciated and a big thank you in advance. 
&lt;br /&gt;
Related posts:&lt;br /&gt;
&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/06/padding-zeros-in-file-name-using-bash.html&quot;&gt;Padding zeros in filename using Bash in UNIX&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/09/rename-file-to-uppercase-except.html&quot;&gt;Rename file to uppercase except extension - Bash&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/09/bash-rename-command-rename-multiple.html&quot;&gt;Rename multiple files using UNIX rename command&lt;/a&gt; &lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/8200153849104201230/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=8200153849104201230' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/8200153849104201230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/8200153849104201230'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/11/unix-append-text-to-filename-using-awk.html' title='UNIX - append text to filename using Awk'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-8247474675029814035</id><published>2012-10-30T21:11:00.002+05:30</published><updated>2012-10-30T21:11:30.905+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk array"/><category scheme="http://www.blogger.com/atom/ns#" term="awk groupby"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="awk NR"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="unix epoch"/><title type='text'>Time bucketing using Awk in Unix</title><content type='html'>Each line of input file file.txt is having UNIX epoch timestamp and some value. 
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat file.txt 
Epoch,Value
1351605000,120
1351605060,130
1351605120,340
1351605180,200
1351605240,120
1351605300,890
1351605360,124
1351605420,450
1351605480,120
1351605540,120
1351605600,200
1351605660,120
1351605720,340
1351605780,670
1351605840,990
&lt;/pre&gt;
The UNIX epoch timestamps are of 1 minute interval. 
Converting the UNIX epoch timestamps to human readable format using awk &#39;strftime&#39; function:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;BEGIN {FS=OFS=&quot;,&quot;} NR != 1 {$1=strftime(&quot;%c&quot;,$1)} {print}&#39; file.txt 
&lt;/pre&gt;
Output:
&lt;br /&gt;
&lt;pre&gt;Epoch,Value
Tue 30 Oct 2012 01:50:00 PM GMT,120
Tue 30 Oct 2012 01:51:00 PM GMT,130
Tue 30 Oct 2012 01:52:00 PM GMT,340
Tue 30 Oct 2012 01:53:00 PM GMT,200
Tue 30 Oct 2012 01:54:00 PM GMT,120
Tue 30 Oct 2012 01:55:00 PM GMT,890
Tue 30 Oct 2012 01:56:00 PM GMT,124
Tue 30 Oct 2012 01:57:00 PM GMT,450
Tue 30 Oct 2012 01:58:00 PM GMT,120
Tue 30 Oct 2012 01:59:00 PM GMT,120
Tue 30 Oct 2012 02:00:00 PM GMT,200
Tue 30 Oct 2012 02:01:00 PM GMT,120
Tue 30 Oct 2012 02:02:00 PM GMT,340
Tue 30 Oct 2012 02:03:00 PM GMT,670
Tue 30 Oct 2012 02:04:00 PM GMT,990
&lt;/pre&gt;
Required:
Group each 5 minutes entries together to one time bucket and perform a corresponding sum(Value) of the entries. 
E.g. All entries from &#39;01:50:00 PM&#39; (1351605000) till &#39;01:54:00 PM&#39; (1351605240) should be grouped together to &#39;01:50:00 PM&#39; (1351605000) time bucket, &#39;01:55:00 PM&#39; (1351605300) till &#39;01:59:00 PM&#39; (1351605540) to &#39;01:55:00 PM&#39; (1351605300) bucket and so on. 
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;BEGIN {FS=OFS=&quot;,&quot;}  NR != 1 {arr[$1-($1%300)]+=$2} END {for (i in arr) print i,arr[i]}&#39; file.txt 
&lt;/pre&gt;
Output:
&lt;br /&gt;
&lt;pre&gt; 
1351605000,910
1351605300,1704
1351605600,2320
&lt;/pre&gt;
Converting UNIX epoch timestamps to human readable format:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;BEGIN {FS=OFS=&quot;,&quot;}  NR != 1 {arr[$1-($1%300)]+=$2} END {for (i in arr) print i,arr[i]}&#39; file.txt  | awk &#39;
BEGIN {FS=OFS=&quot;,&quot;} {$1=strftime(&quot;%c&quot;,$1)} {print}&#39;
&lt;/pre&gt;
Output:
&lt;br /&gt;
&lt;pre&gt;Tue 30 Oct 2012 01:50:00 PM GMT,910
Tue 30 Oct 2012 01:55:00 PM GMT,1704
Tue 30 Oct 2012 02:00:00 PM GMT,2320
&lt;/pre&gt;
Related posts:&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/10/grouping-files-using-awk-in-bash-shell.html&quot;&gt;Grouping files using Awk in Bash shell&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2011/06/awk-convert-epoch-to-date-in-same-file.html&quot;&gt;Awk convert epoch to date format&lt;/a&gt; &lt;br /&gt;
- SUM and GROUP BY using Awk in UNIX &lt;a href=&quot;http://unstableme.blogspot.in/2008/09/sum-of-and-group-by-using-awk.html&quot;&gt;post1&lt;/a&gt; &lt;a href=&quot;http://unstableme.blogspot.in/2008/09/group-by-clause-functionality-in-awk.html&quot;&gt;post2&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/05/count-number-of-occurrences-using-awk.html&quot;&gt;COUNT number of occurrences using Awk&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/05/associative-array-in-awk.html&quot;&gt;Awk Associative array&lt;/a&gt; &lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/8247474675029814035/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=8247474675029814035' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/8247474675029814035'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/8247474675029814035'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/10/time-bucketing-using-awk-in-unix.html' title='Time bucketing using Awk in Unix'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-3090955568447045663</id><published>2012-09-30T14:06:00.001+05:30</published><updated>2012-09-30T14:08:14.103+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk for loop"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="linux cut"/><title type='text'>Awk - separate last field with spaces</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Each line of following file &#39;file.txt&#39; actually has total 4 fields/columns. As you can see some of the values of the last field (4th field, header : Description) has spaces in them. 
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat file.txt 
ID Name Active Description
2312 DEMO-1 1 Demo for VOD LIVE
1245 DEMO-4 1 LIVE
1002 CUST2 0 VOD Event
19000 DEMO-2 1 VOD
189 DEMO-3 1 Demo for LIVE
&lt;/pre&gt;
Required output:&lt;/br&gt;
We need to separate the 4 fields with a comma (,) delimiter such that all the values after 3rd field is considered as 4th field/column.
i.e. Required output is something like this:
&lt;br /&gt;
&lt;pre&gt;ID, Name, Active, Description
2312, DEMO-1, 1, Demo for VOD LIVE
1245, DEMO-4, 1, LIVE
1002, CUST2, 0, VOD Event
19000, DEMO-2, 1, VOD
189, DEMO-3, 1, Demo for LIVE
&lt;/pre&gt;
One way to achieve this is to add comma (,) to each of the first 3 fields of every line/row.
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39; { for ( i=1;i&amp;lt;=3;i++ ) {$i=$i&quot;,&quot;} print }&#39; file.txt
&lt;/pre&gt;
Output:
&lt;br /&gt;
&lt;pre&gt;ID, Name, Active, Description
2312, DEMO-1, 1, Demo for VOD LIVE
1245, DEMO-4, 1, LIVE
1002, CUST2, 0, VOD Event
19000, DEMO-2, 1, VOD
189, DEMO-3, 1, Demo for LIVE
&lt;/pre&gt;
Any other alternative ? Feel free to post in the comment section, much appreciated. Thanks. &lt;/br&gt;
&lt;/br&gt;
And to print the last field of the above input file one solution using UNIX cut command:
&lt;/br&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cut -d&quot; &quot; -f4- file.txt
&lt;/pre&gt;
Output:
&lt;br /&gt;
&lt;pre&gt;Description
Demo for VOD LIVE
LIVE
VOD Event
VOD
Demo for LIVE
&lt;/pre&gt;
Related posts:&lt;/br&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/01/awk-change-field-separator-add-line.html&quot;&gt;Awk change field separator or delimiter of a file&lt;/a&gt; &lt;/br&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2010/11/sort-file-based-on-last-field-unix.html&quot;&gt;UNIX sort file based on last field&lt;/a&gt;&lt;/br&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/04/print-last-field-grep.html&quot;&gt;Different ways to print last field of line in UNIX command line&lt;/a&gt;&lt;/br&gt;


&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/3090955568447045663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=3090955568447045663' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3090955568447045663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3090955568447045663'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/09/awk-separate-last-field-with-spaces.html' title='Awk - separate last field with spaces'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-1068307941261542759</id><published>2012-09-26T23:15:00.002+05:30</published><updated>2012-09-26T23:15:16.789+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash join"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="linux paste"/><title type='text'>Compare two numeric fields of two files - UNIX awk</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Following example will show how we can use UNIX paste and join command with awk to find difference of two numeric columns of two similar files. &lt;br /&gt;
&lt;br /&gt;
e.g. Input file:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat file1.txt 
Aug-1,100
Aug-2,220
Aug-4,230
Aug-5,100

&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat file2.txt 
Aug-1,100
Aug-2,120
Aug-4,400
Aug-5,250
&lt;/pre&gt;
Required output:&lt;br /&gt;
As you can see both file1.txt and file2.txt has got first field (comma separated) in the same order. 
We will have to find out the corresponding (2nd field of file1.txt - 2nd field of file2.txt) and the output required is something like this:
&lt;br /&gt;
&lt;pre&gt;Aug-1,100,100,0
Aug-2,220,120,100
Aug-4,230,400,-170
Aug-5,100,250,-150
&lt;/pre&gt;
Solution#1:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; paste -d &quot;,&quot; file1.txt file2.txt
Aug-1,100,Aug-1,100
Aug-2,220,Aug-2,120
Aug-4,230,Aug-4,400
Aug-5,100,Aug-5,250

&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; paste -d &quot;,&quot; file1.txt file2.txt | awk &#39;BEGIN {FS=OFS=&quot;,&quot;} {print $1,$2,$NF,$2-$NF}&#39;
Aug-1,100,100,0
Aug-2,220,120,100
Aug-4,230,400,-170
Aug-5,100,250,-150
&lt;/pre&gt;
Solution#2:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; join -t, -1 1 -2 1 file1.txt file2.txt 
Aug-1,100,100
Aug-2,220,120
Aug-4,230,400
Aug-5,100,250

&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; join -t, -1 1 -2 1 file1.txt file2.txt | awk &#39; BEGIN {FS=OFS=&quot;,&quot;} {print $0,$2-$NF}&#39;
Aug-1,100,100,0
Aug-2,220,120,100
Aug-4,230,400,-170
Aug-5,100,250,-150
&lt;/pre&gt;
Some similar posts:&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/01/linux-paste-command-good-examples-uses.html&quot;&gt;A small tutorial on UNIX paste command&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/03/performing-join-using-awk.html&quot;&gt;Performing join using awk&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2007/12/command-in-discussion-join-bash.html&quot;&gt;Join in bash&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/06/perform-outer-join-bash-join-command.html&quot;&gt;Perform outer join in UNIX Bash&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2010/02/bash-find-diff-based-on-field.html&quot;&gt;Find diff based on field - UNIX Bash&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/1068307941261542759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=1068307941261542759' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1068307941261542759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/1068307941261542759'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/09/compare-two-numeric-fields-of-two-files.html' title='Compare two numeric fields of two files - UNIX awk'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-2948807718491628351</id><published>2012-07-23T10:20:00.000+05:30</published><updated>2012-07-23T10:20:02.676+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="awk variable assignment"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><title type='text'>Print double quotes in unix Awk</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I have already described in one of the earlier &lt;a href=&quot;http://unstableme.blogspot.in/2009/11/printing-single-quote-in-awk-bash.html&quot;&gt;posts&lt;/a&gt; on how to print string within single quote in Awk print statement. Here is how we can print strings without &quot;double quotes&quot; in Awk. &lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat file.txt 
6289693505455 Plan_DAIL_30D_AA
6289693505475 Plan_DAIL_30D_AA
6289693505462 Plan_DAIL_30D_AB
&lt;/pre&gt;
Output required:
&lt;br /&gt;
&lt;pre&gt;Plan_DAIL_30D_AA &quot;6289693505455&quot;
Plan_DAIL_30D_AA &quot;6289693505475&quot;
Plan_DAIL_30D_AB &quot;6289693505462&quot;
&lt;/pre&gt;
i.e. Print the first field of the file within &quot;double quotes&quot;. &lt;br /&gt;
Here are some of the alternatives:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;{print $2,$1}&#39; file.txt 
Plan_DAIL_30D_AA 6289693505455
Plan_DAIL_30D_AA 6289693505475
Plan_DAIL_30D_AB 6289693505462

&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;{print $2,&quot;\&quot;&quot;$1&quot;\&quot;&quot;}&#39; file.txt 
Plan_DAIL_30D_AA &quot;6289693505455&quot;
Plan_DAIL_30D_AA &quot;6289693505475&quot;
Plan_DAIL_30D_AB &quot;6289693505462&quot;

#Assigning the quotes sequence to a variable x 
&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk -v x=&quot;\&quot;&quot; &#39;{print $2,x$1x}&#39; file.txt 
Plan_DAIL_30D_AA &quot;6289693505455&quot;
Plan_DAIL_30D_AA &quot;6289693505475&quot;
Plan_DAIL_30D_AB &quot;6289693505462&quot;

#Using octal code of double quotes
&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;{print $2,&quot;\042&quot;$1&quot;\042&quot;}&#39; file.txt 
Plan_DAIL_30D_AA &quot;6289693505455&quot;
Plan_DAIL_30D_AA &quot;6289693505475&quot;
Plan_DAIL_30D_AB &quot;6289693505462&quot;

#Using ASCII code of double quotes
&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; awk &#39;{print $2,&quot;\x22&quot;$1&quot;\x22&quot;}&#39;  file.txt 
Plan_DAIL_30D_AA &quot;6289693505455&quot;
Plan_DAIL_30D_AA &quot;6289693505475&quot;
Plan_DAIL_30D_AB &quot;6289693505462&quot;
&lt;/pre&gt;
Related posts:
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/03/accessing-external-variable-in-awk-and.html&quot;&gt;Accessing external variable in Awk and Sed&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/2948807718491628351/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=2948807718491628351' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/2948807718491628351'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/2948807718491628351'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/07/print-double-quotes-in-unix-awk.html' title='Print double quotes in unix Awk'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-7437815175378290288</id><published>2012-07-12T10:30:00.000+05:30</published><updated>2012-07-12T10:30:43.611+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="bash sort"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Commands"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><title type='text'>Unix sort file ignoring first line</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Input file:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; cat file.txt 
chrom:index:forward:reverse
chr01:13:1:2
chr03:12:1:4
chr01:3445:1:6
chr02:2311:3:1
chr13:23432:4:7
chr01:212:5:2
chr02:345:12:6
chr01:45:45:0
&lt;/pre&gt;
Output required:
&lt;br /&gt;
&lt;pre&gt; 
chrom:index:forward:reverse
chr01:13:1:2
chr01:45:45:0
chr01:212:5:2
chr01:3445:1:6
chr02:345:12:6
chr02:2311:3:1
chr03:12:1:4
chr13:23432:4:7
&lt;/pre&gt;
i.e. 
Sort file.txt ignoring the header line (1st line).&lt;br /&gt;
Sort first field in ascending order (string)&lt;br /&gt;
Sort second field in ascending order (numeric)&lt;br /&gt;
One of the solution would be:&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;$&lt;/span&gt; head -1 file.txt ; tail -n +2 file.txt | sort -t : -k1,1 -k2,2n
&lt;/pre&gt;
As you can see two commands are combined together to satisfy the output. &lt;br /&gt;
i) First part is printing the first line of file.txt &lt;br /&gt;
ii) Second part is printing the lines except first line and then sorting the lines based on first field (string) and second field (numeric sort). &lt;br /&gt;
Related posts: &lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2010/11/sort-file-based-on-last-field-unix.html&quot;&gt;Unix sort file based on last field&lt;/a&gt; &lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2009/08/sort-strings-by-length-using-awk-and.html&quot;&gt;Sort strings by length using Awk&lt;/a&gt; &lt;br /&gt;
- &lt;a href=&quot;http://unstableme.blogspot.in/2008/08/sort-date-in-ddmmyyyy-format-awk-and.html&quot;&gt;Unix sort date in ddmmyyyy format using Awk&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/7437815175378290288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=7437815175378290288' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/7437815175378290288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/7437815175378290288'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/07/unix-sort-file-ignoring-first-line.html' title='Unix sort file ignoring first line'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-3492789565525484771</id><published>2012-02-18T19:58:00.002+05:30</published><updated>2012-02-18T20:09:28.294+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="awk for loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash loop"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Commands"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><category scheme="http://www.blogger.com/atom/ns#" term="nohup"/><title type='text'>Run UNIX bash loop with nohup</title><content type='html'>Suppose we have to run following UNIX bash shell loop construct under &#39;nohup&#39;&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; for i in $(seq 20); do echo $i;./somescript.sh $i; done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Running the above loop under nohup directly will not work as &#39;nohup&#39; expects a single-word command and its arguments. This is how we can run a UNIX bash shell loop construct using &#39;nohup&#39;.&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; nohup sh -c &#39;for i in $(seq 20); do echo $i;./somescript.sh $i; done&#39; &amp;amp;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;From man page of &#39;sh&#39;&lt;br /&gt;&lt;pre&gt;-c               Read commands from the command_string operand instead of from the&lt;br /&gt;standard input.  Special parameter 0 will be set from the command_name operand&lt;br /&gt;and the positional parameters ($1, $2, etc.)  set from the remaining argument operands.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Related post:&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.in/2008/03/setsid-keep-linux-program-running-while.html&quot;&gt;Setsid : Run UNIX program in a new session&lt;/a&gt;&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.in/2007/02/generating-loop-arguments-seq-command.html&quot;&gt;More about UNIX seq command&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/3492789565525484771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=3492789565525484771' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3492789565525484771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3492789565525484771'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2012/02/run-unix-bash-loop-with-nohup.html' title='Run UNIX bash loop with nohup'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-3289487118266619089</id><published>2011-10-28T09:32:00.002+05:30</published><updated>2011-10-28T09:46:42.097+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Commands"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Utilities"/><category scheme="http://www.blogger.com/atom/ns#" term="Unix less"/><title type='text'>Print line number with unix less command</title><content type='html'>&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;Less command introduction:&lt;/span&gt;&lt;br /&gt;As you know Unix less command writes the contents of a file onto the screen a page at a time and this is one of the utilities using which one can view the content of a file without opening it in an editor.&lt;br /&gt;Press the [space-bar] if you want to see another page, and type [q] if you want to quit reading.&lt;br /&gt;&lt;br /&gt;This is how we can print line number with Unix less command.&lt;br /&gt;&lt;br /&gt;1)&lt;br /&gt;From man page of CAT(1):&lt;br /&gt;&lt;pre&gt;       -n, --number&lt;br /&gt;              number all output lines&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So,&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; cat -n file.txt | less&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;will print the line number in-front of each line.&lt;br /&gt;&lt;br /&gt;2)&lt;br /&gt;From man page of LESS(1):&lt;br /&gt;&lt;pre&gt;       -N or --LINE-NUMBERS&lt;br /&gt;              Causes a line number to be displayed at the beginning of each line in the display.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So,&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(204, 0, 0);&quot;&gt;$&lt;/span&gt; less -N file.txt&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;will do the same as 1) above.&lt;br /&gt;&lt;br /&gt;3) One can set the following to print line number with less by default:&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(204, 0, 0);&quot;&gt;$&lt;/span&gt; export LESS=&#39;-RS#3NM~g&#39;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://4.bp.blogspot.com/-B3ZVikgEGpk/TqopZz9IMzI/AAAAAAAADcA/4Tt6V1rLxnU/s1600/Unix%2Bless%2Bcommand%2B-%2Bline%2Bnumber.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 305px; height: 364px;&quot; src=&quot;http://4.bp.blogspot.com/-B3ZVikgEGpk/TqopZz9IMzI/AAAAAAAADcA/4Tt6V1rLxnU/s400/Unix%2Bless%2Bcommand%2B-%2Bline%2Bnumber.png&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5668388604419257138&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;Related posts:&lt;/span&gt;&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.com/2009/11/bash-numbering-lines-in-file-using-awk.html&quot;&gt;Numbering lines in a file using Bash awk&lt;/a&gt;&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.com/2010/11/vi-open-file-at-required-line-number.html&quot;&gt;Open file at required line number in Unix vi editor&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/3289487118266619089/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=3289487118266619089' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3289487118266619089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3289487118266619089'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2011/10/print-line-number-with-unix-less.html' title='Print line number with unix less command'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-B3ZVikgEGpk/TqopZz9IMzI/AAAAAAAADcA/4Tt6V1rLxnU/s72-c/Unix%2Bless%2Bcommand%2B-%2Bline%2Bnumber.png" height="72" width="72"/><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-3273895674222926536</id><published>2011-06-27T22:07:00.004+05:30</published><updated>2011-06-27T22:31:17.965+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="Awk strftime"/><category scheme="http://www.blogger.com/atom/ns#" term="awk substr"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="python newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="unix epoch"/><title type='text'>Awk - convert epoch to date in the same file</title><content type='html'>&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;Example 1)&lt;/span&gt;&lt;br /&gt;Input file:&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; cat test1.txt&lt;br /&gt;2|Z|1219071600|AF|0&lt;br /&gt;3|N|1219158000|AF|89&lt;br /&gt;4|N|1220799600|AS|12&lt;br /&gt;1|Z|1220886000|AS|67&lt;br /&gt;5|N|1220972400|EU|23&lt;br /&gt;6|R|1221058800|OC|89&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Required output:&lt;br /&gt;&lt;pre&gt;2|Z|Mon 18 Aug 2008 03:00:00 PM UTC|AF|0&lt;br /&gt;3|N|Tue 19 Aug 2008 03:00:00 PM UTC|AF|89&lt;br /&gt;4|N|Sun 07 Sep 2008 03:00:00 PM UTC|AS|12&lt;br /&gt;1|Z|Mon 08 Sep 2008 03:00:00 PM UTC|AS|67&lt;br /&gt;5|N|Tue 09 Sep 2008 03:00:00 PM UTC|EU|23&lt;br /&gt;6|R|Wed 10 Sep 2008 03:00:00 PM UTC|OC|89&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;i.e. convert the UNIX epoch values on 3 rd field of the above file to standard human readable date format using Awk.&lt;br /&gt;&lt;br /&gt;The Awk solution using &quot;strftime&quot; function:&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; awk &#39;BEGIN {FS=OFS=&quot;|&quot;}{$3=strftime(&quot;%c&quot;,$3)} {print}&#39; test1.txt&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;More about strftime format specifiers can be found &lt;a href=&quot;http://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have created a python program to achieve the above output and the script is &lt;a href=&quot;http://pythonstarter.blogspot.com/2009/04/apply-operation-on-field-python.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;Example 2) &lt;/span&gt;&lt;br /&gt;Input file:&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; cat test2.txt&lt;br /&gt;2|Z|time:1219071600|AF|0&lt;br /&gt;3|N|time:1219158000|AF|89&lt;br /&gt;4|N|time:1220799600|AS|12&lt;br /&gt;1|Z|time:1220886000|AS|67&lt;br /&gt;5|N|time:1220972400|EU|23&lt;br /&gt;6|R|time:1221058800|OC|89&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Required output:&lt;br /&gt;&lt;pre&gt;2|Z|time:Mon 18 Aug 2008 03:00:00 PM UTC|AF|0&lt;br /&gt;3|N|time:Tue 19 Aug 2008 03:00:00 PM UTC|AF|89&lt;br /&gt;4|N|time:Sun 07 Sep 2008 03:00:00 PM UTC|AS|12&lt;br /&gt;1|Z|time:Mon 08 Sep 2008 03:00:00 PM UTC|AS|67&lt;br /&gt;5|N|time:Tue 09 Sep 2008 03:00:00 PM UTC|EU|23&lt;br /&gt;6|R|time:Wed 10 Sep 2008 03:00:00 PM UTC|OC|89&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The awk solution:&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; awk &#39;BEGIN {FS=OFS=&quot;|&quot;}{$3=&quot;time:&quot;strftime(&quot;%c&quot;,substr($3,6,10))} {print}&#39; test2.txt&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Related posts:&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.com/2008/05/awk-substr-function.html&quot;&gt;Awk Substr function explained&lt;/a&gt;&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.com/2009/09/print-first-character-of-field-awk.html&quot;&gt;Print first character of a field in a file using Awk&lt;/a&gt;&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.com/2009/12/replace-first-5-characters-awk-and-sed.html&quot;&gt;Replace first 5 characters of a file using UNIX Sed and Awk&lt;/a&gt;&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.com/2009/11/convert-fixed-length-file-to-csv-awk.html&quot;&gt;Convert fixed length file to a CSV file using Awk&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/3273895674222926536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=3273895674222926536' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3273895674222926536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/3273895674222926536'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2011/06/awk-convert-epoch-to-date-in-same-file.html' title='Awk - convert epoch to date in the same file'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8796493175195266816.post-8206084283696865652</id><published>2011-06-20T22:09:00.003+05:30</published><updated>2011-06-20T22:25:21.377+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Awk"/><category scheme="http://www.blogger.com/atom/ns#" term="awk array"/><category scheme="http://www.blogger.com/atom/ns#" term="awk if else"/><category scheme="http://www.blogger.com/atom/ns#" term="awk newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="awk split"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash"/><category scheme="http://www.blogger.com/atom/ns#" term="bash for"/><category scheme="http://www.blogger.com/atom/ns#" term="Bash if else"/><category scheme="http://www.blogger.com/atom/ns#" term="bash shell newbie"/><category scheme="http://www.blogger.com/atom/ns#" term="bash while"/><title type='text'>Filter line using Awk split function</title><content type='html'>Input file &quot;file.txt&quot; has data in the following format:&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; cat file.txt&lt;br /&gt;232323 90 /T/1382/8558/365p/133 100 234 679&lt;br /&gt;S/1234 90 /N/1389/&lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;5000&lt;/span&gt;/365s/5000 800 134 679&lt;br /&gt;792363 80 /T/1381/9858/365q/133 100 234 779&lt;br /&gt;136383 90 /K/1382/&lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;5000&lt;/span&gt;/365p/5000 500 934 979&lt;br /&gt;136383 90 /T/1382/&lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;5000&lt;/span&gt;/279p/9000 100 134 601&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Required output:&lt;/span&gt; From the above file print only the lines whose 3rd field has the value &quot;5000&quot; as the 4th field (separated by the delimiter &quot;/&quot;) in it. i.e. required output:&lt;br /&gt;&lt;pre&gt;S/1234 90 /N/1389/&lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;5000&lt;/span&gt;/365s/5000 800 134 679&lt;br /&gt;136383 90 /K/1382/&lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;5000&lt;/span&gt;/365p/5000 500 934 979&lt;br /&gt;136383 90 /T/1382/&lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;5000&lt;/span&gt;/279p/9000 100 134 601&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Using awk:&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; awk &#39;{&lt;br /&gt;    split($3,arr,&quot;/&quot;)&lt;br /&gt;    if(arr[4] == 5000) {&lt;br /&gt;        print $0&lt;br /&gt;        }&lt;br /&gt;}&#39; file.txt&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The awk function split(s,a,sep) splits a string &quot;s&quot; into an awk array &quot;a&quot; using the delimiter &quot;sep&quot;.&lt;br /&gt;&lt;br /&gt;A simple UNIX bash script to solve this:&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;$&lt;/span&gt; while read line&lt;br /&gt;    do &lt;br /&gt;        thirdf=$(echo &quot;$line&quot; | awk &#39;{print $3}&#39;)&lt;br /&gt;        fourthf=$(echo &quot;$thirdf&quot; | awk -F &quot;/&quot; &#39;{print $4}&#39;)&lt;br /&gt;        [ &quot;$fourthf&quot; -eq 5000 ] &amp;amp;&amp;amp; echo $line&lt;br /&gt;done &amp;lt; file.txt&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Related posts:&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.com/2008/06/add-prefix-to-lines-using-awk-bash.html&quot;&gt;Add prefix to lines in a file using awk and bash&lt;/a&gt;&lt;br /&gt;- &lt;a href=&quot;http://unstableme.blogspot.com/2011/05/awk-replace-n-th-occurrence-of-pattern.html&quot;&gt;Replace n-th occurrence of pattern in a file using Awk&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.unixcl.com/feeds/8206084283696865652/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8796493175195266816&amp;postID=8206084283696865652' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/8206084283696865652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8796493175195266816/posts/default/8206084283696865652'/><link rel='alternate' type='text/html' href='http://www.unixcl.com/2011/06/filter-line-using-awk-split-function.html' title='Filter line using Awk split function'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/00278385409494551967</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry></feed>