<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Scripting on Bilal Syed Hussain</title>
    <link>https://bilalh.github.io/topics/scripting/</link>
    <description>Recent content in Scripting on Bilal Syed Hussain</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-EN</language>
    <managingEditor>bilalshussain@gmail.com (Bilal Syed Hussain)</managingEditor>
    <webMaster>bilalshussain@gmail.com (Bilal Syed Hussain)</webMaster>
    <copyright>(c) 2015 Bilal Syed Hussain.</copyright>
    <lastBuildDate>Sat, 31 Oct 2015 16:46:31 +0000</lastBuildDate>
    <atom:link href="https://bilalh.github.io/topics/scripting/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Viewing .csv files on the command line</title>
      <link>https://bilalh.github.io/2015/10/31/viewing-.csv-files-on-the-command-line/</link>
      <pubDate>Sat, 31 Oct 2015 16:46:31 +0000</pubDate>
      <author>bilalshussain@gmail.com (Bilal Syed Hussain)</author>
      <guid>https://bilalh.github.io/2015/10/31/viewing-.csv-files-on-the-command-line/</guid>
      <description>&lt;p&gt;It can be convenient to view a &lt;code&gt;.csv&lt;/code&gt; file from the command line, when using SSH connection for example.  A basic version with no dependencies is as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;function see_csv(){
    column -s, -t &amp;lt;&amp;quot;$1&amp;quot; | less --shift 2  -SN
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;with example output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;1 seq    run_no  kind        iterations  timeout
2 12001  1       undirected  64          600
3 12002  1       nsample     64          600
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To handle blank fields we can use &lt;code&gt;sed&lt;/code&gt; to add extra spaces for use with &lt;code&gt;column&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;function see_csv(){
    cat &amp;quot;$1&amp;quot; | sed &#39;s/,,/, ,/g;s/,,/, ,/g&#39; | column -s, -t | less --shift 2 -SN
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If the &lt;code&gt;.csv&lt;/code&gt; has many columns, you change the &lt;code&gt;less&lt;/code&gt; options to the following:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;function see_csv(){
    cat &amp;quot;$1&amp;quot; | sed &#39;s/,,/, ,/g;s/,,/, ,/g&#39; | column -s, -t | less -SN -Xs
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So that the columns that can fit on the screen are printed, for convenience.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;❯ see_csv experiment.csv
      1 seq    run_no  kind        iterations param timeout  
      2 16001  1       undirected  64               38400            
      3 16002  1       nsample     64               38400            
      4 16003  1       undirected  64               38400            

~/Desktop/Results/
❯

~/Desktop/Results/
❯
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To access any addition columns use the arrow keys, this will cause the screen to be redrawn.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Alfred Extensions</title>
      <link>https://bilalh.github.io/2013/03/29/alfred-extensions/</link>
      <pubDate>Fri, 29 Mar 2013 00:15:21 +0000</pubDate>
      <author>bilalshussain@gmail.com (Bilal Syed Hussain)</author>
      <guid>https://bilalh.github.io/2013/03/29/alfred-extensions/</guid>
      <description>

&lt;p&gt;Workflows and Extensions for &lt;a href=&#34;www.alfredapp.com&#34;&gt;Alfred&lt;/a&gt; hosted on &lt;a href=&#34;https://github.com/Bilalh/AlfredExtensions&#34;&gt;https://github.com/Bilalh/AlfredExtensions&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;itunes-ratings&#34;&gt;iTunes Ratings&lt;/h2&gt;

&lt;p&gt;Allows you to set the rating of the currently playing song. Support halves stars and empty ratings&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://bilalh.github.io/media/posts/alfred_itunes.png
&#34; alt=&#34;Alfred iTunes&#34; /&gt;&lt;/p&gt;

&lt;p&gt;based off &lt;a href=&#34;https://github.com/qlassiqa/qWorkflow/tree/master/example%20workflows&#34;&gt;https://github.com/qlassiqa/qWorkflow/tree/master/example%20workflows&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;toggle-extension&#34;&gt;Toggle Extension&lt;/h2&gt;

&lt;p&gt;A file action which toggles the visibility of file extensions for the selected files&lt;/p&gt;

&lt;h2 id=&#34;shellmarks&#34;&gt;Shellmarks&lt;/h2&gt;

&lt;p&gt;Allow the use of &lt;a href=&#34;https://bilalh.github.io/2012/01/14/shellmarks---terminal-directory-bookmarks/&#34;&gt;Shellmarks&lt;/a&gt;,  a shell script that allows you to save and jump to commonly used directories from Alfred.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Pipe output from command line tools to a text editor</title>
      <link>https://bilalh.github.io/2012/04/22/pipe-output-from-command-line-tools-to-a-text-editor/</link>
      <pubDate>Sun, 22 Apr 2012 22:01:23 +0000</pubDate>
      <author>bilalshussain@gmail.com (Bilal Syed Hussain)</author>
      <guid>https://bilalh.github.io/2012/04/22/pipe-output-from-command-line-tools-to-a-text-editor/</guid>
      <description>&lt;p&gt;A useful feature is to pipe the result of a command such as &lt;code&gt;ls&lt;/code&gt; to a text editor. This can be done by using:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;	ls | open -f
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Using the &lt;code&gt;-a&lt;/code&gt; flag for &lt;code&gt;open&lt;/code&gt;  makes this even more useful allowing you to specify the application to open the output in e.g to open in TextMate use:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;	ls | open -f -a Textmate
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
    <item>
      <title>Shellmarks - terminal directory bookmarks</title>
      <link>https://bilalh.github.io/2012/01/14/shellmarks---terminal-directory-bookmarks/</link>
      <pubDate>Sat, 14 Jan 2012 00:57:33 +0000</pubDate>
      <author>bilalshussain@gmail.com (Bilal Syed Hussain)</author>
      <guid>https://bilalh.github.io/2012/01/14/shellmarks---terminal-directory-bookmarks/</guid>
      <description>

&lt;p&gt;&lt;a href=&#34;https://bilalh.github.io/shellmarks
&#34; title=&#34;shellmarks project page&#34;&gt;shellmarks&lt;/a&gt; is a shell script that allows you to save and jump to commonly used directories.&lt;/p&gt;

&lt;h2 id=&#34;usage-example&#34;&gt;Usage Example&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;$ cd /var/www/
$ s web
$ cd /usr/local/bin/
$ s localbin
$ l
    web          /var/www/
    localbin     /usr/local/bin/
$ g web&amp;lt;tab&amp;gt;
$ g web          # cd to /var/www/
$ o web     	 # Open in Finder if on a mac
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;extra-features&#34;&gt;Extra Features&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;if no bookmark name is specified the default directory is used instead  ($HOME unless changed)&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;cd ~/projects
s
g              # g now defaults to ~/projects
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Commands can be placed after the bookmark&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;$ g web ls     # cd to ~/home/projects/www/ then executes ls
~/var/www/
index.html
site.css
$
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;cd like features&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;g -   # does cd -
g ..  # does cd ..
g /   # does cd /
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;mac-specific-features&#34;&gt;Mac Specific Features&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;o&lt;/code&gt; command which opens the specified bookmark in Finder&lt;/li&gt;
&lt;li&gt;&lt;code&gt;t&lt;/code&gt; command which opens the specified bookmark in a new Terminal tab.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;y web          # opens ~/home/projects/www/  in a new tab
cd javascript
y              # opens ~/home/projects/www/javascript in a new tab

o              # opens ~/home/projects/www/javascript in Finder
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;install&#34;&gt;Install&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;git clone git://github.com/Bilalh/shellmarks.git&lt;/li&gt;
&lt;li&gt;make install&lt;/li&gt;
&lt;li&gt;&lt;code&gt;source ~/.local/bin/shellmarks.sh&lt;/code&gt; from within your &lt;code&gt;~.bash_profile&lt;/code&gt; or &lt;code&gt;~/.bashrc&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;p&gt;download &lt;a href=&#34;https://raw.githubusercontent.com/Bilalh/shellmarks/master/shellmarks.sh&#34;&gt;https://raw.githubusercontent.com/Bilalh/shellmarks/master/shellmarks.sh&lt;/a&gt; and source it from within your &lt;code&gt;~.bash_profile&lt;/code&gt; or &lt;code&gt;~/.bashrc&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&#34;more-information&#34;&gt;More Information&lt;/h2&gt;

&lt;p&gt;See the &lt;a href=&#34;https://bilalh.github.io/shellmarks
&#34; title=&#34;shellmarks project page&#34;&gt;project page&lt;/a&gt;  for information.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Useful sed commands</title>
      <link>https://bilalh.github.io/2011/10/09/useful-sed-commands/</link>
      <pubDate>Sun, 09 Oct 2011 17:20:59 +0000</pubDate>
      <author>bilalshussain@gmail.com (Bilal Syed Hussain)</author>
      <guid>https://bilalh.github.io/2011/10/09/useful-sed-commands/</guid>
      <description>

&lt;h3 id=&#34;delete-nth-line-inplace&#34;&gt;Delete nth line inplace&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sed -i .tmp &#39;&amp;lt;n&amp;gt;d&#39; &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;get-the-nth-line&#34;&gt;Get the nth line&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sed &#39;&amp;lt;n&amp;gt;q;d&#39; &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;delete-the-first-10-lines-of-a-file&#34;&gt;Delete the first 10 lines of a file&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sed &#39;1,10d&#39;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;delete-lines-matching-pattern&#34;&gt;Delete lines matching pattern&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt; sed &#39;/pattern/d&#39;
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
  </channel>
</rss>