<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dammit Jim! &#187; Bash/UNIX</title>
	<atom:link href="http://scott.sherrillmix.com/blog/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://scott.sherrillmix.com/blog</link>
	<description>I'm a biologist not a...</description>
	<lastBuildDate>Mon, 06 Feb 2012 05:19:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Syntax highlighting in terminal</title>
		<link>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:53:09 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[cat]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[pygmentize]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=526</guid>
		<description><![CDATA[I was just quickly flipping through code on a terminal and got to thinking that it would be pretty handy to be able to syntax highlight when using head or grep without having to open an editor. Luckily, I remembered Pygmentize was pretty handy when syntax highlighting in LaTeX so I wondered if they had [...]]]></description>
			<content:encoded><![CDATA[<img src="/res/images/ccat.png" alt="Syntax highlighted cat" class="right"/>
<p>I was just quickly flipping through code on a terminal and got to thinking that it would be pretty handy to be able to syntax highlight when using <code>head</code> or <code>grep</code> without having to open an editor. Luckily, I remembered <a href="http://pygments.org/">Pygmentize</a> was pretty handy when <a href="http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/">syntax highlighting in LaTeX</a> so I wondered if they had an equivalent output for terminal. It turns out they do (in standard or 256 color no less) so in a couple minutes I had a really short script for highlighting code at the terminal saved it to <code>bin/ccat</code> and was ready to go. Pygmentize really is impressive. Here's the script if anyone else is looking to do the same:</p>
<div class="syntax_hilite"><span class="langName">BASH:</span><br /><div id="bash-2">
<div class="bash"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#!/bin/bash#!/bin/bash</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> ! -t <span style="color: #cc66cc;color:#800000;">0</span> <span style="color: #66cc66;">&#93;</span>;then</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">file=</span>/dev/stdin</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">elif</span> <span style="color: #66cc66;">&#91;</span> -f $<span style="color: #cc66cc;color:#800000;">1</span> <span style="color: #66cc66;">&#93;</span>;then</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">file=</span>$<span style="color: #cc66cc;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"Usage: $0 code.c"</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"or e.g. head code.c|$0"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">exit</span> <span style="color: #cc66cc;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">fi</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pygmentize -f terminal -g <span style="color: #0000ff;">$file</span> </div></li></ol></div>
</div></div><br />
<p>It just looks for stdin and if it doesn't find it it looks for a file name or takes direct input. Obviously it requires Pygmentize (which is really <a href="http://pygments.org/download/">easy to install</a> if you already have Python).</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tab Indented Standard Input Redirect in Bash</title>
		<link>http://scott.sherrillmix.com/blog/programmer/tab-indented-standard-input-redirect-in-bash/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/tab-indented-standard-input-redirect-in-bash/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 02:52:43 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[EOF]]></category>
		<category><![CDATA[indent]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[standard input]]></category>
		<category><![CDATA[tab]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=502</guid>
		<description><![CDATA[I managed to forget how to redirect standard input (when you want to feed a bunch of lines to a program) in a bash script while still indenting and had to go digging around for it. So I figured I'd make a note here so I don't forget again and for anyone else in the [...]]]></description>
			<content:encoded><![CDATA[<p>I managed to forget how to redirect standard input (when you want to feed a bunch of lines to a program) in a bash script while still indenting and had to go digging around for it. So I figured I'd make a note here so I don't forget again and for anyone else in the same boat. It's just <code>&lt;&lt;-</code> instead of <code>&lt;&lt;</code>. For example if you want to keep indentation within a loop:</p>
<div class="syntax_hilite"><span class="langName">BASH:</span><br /><div id="bash-4">
<div class="bash"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">for</span> i <span style="color: #b1b100;">in</span> <span style="color: #cc66cc;color:#800000;">1</span> <span style="color: #cc66cc;color:#800000;">2</span> <span style="color: #cc66cc;color:#800000;">3</span> <span style="color: #cc66cc;color:#800000;">4</span>;do</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; cat&lt;&lt;-EOF</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; This is loop <span style="color: #0000ff;">$i</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; More advanced stuff could go here</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; EOF</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">done</span> </div></li></ol></div>
</div></div><br />
<p>You can use whatever you want to indicate the end of the input instead of EOF if it floats your boat (as long as you use the same thing both times) but unfortunately <code>&lt;&lt;-</code> doesn't work with spaces for indentation (although I'm a tab man myself).</p>
]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/tab-indented-standard-input-redirect-in-bash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Counting Q20 Bases in a .qual File</title>
		<link>http://scott.sherrillmix.com/blog/biologist/counting-q20-bases-in-a-qual-file/</link>
		<comments>http://scott.sherrillmix.com/blog/biologist/counting-q20-bases-in-a-qual-file/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 16:43:17 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Bioinformatics]]></category>
		<category><![CDATA[Biologist]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[Q20]]></category>
		<category><![CDATA[qual]]></category>
		<category><![CDATA[qualities]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[sequencing]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=422</guid>
		<description><![CDATA[I sometimes get asked to count the number of bases with qualities greater than or equal to 20 in a quality file. I'm not entirely sure this is all that good a metric with 454 sequencing but that's another story. It always takes me a minute or two to come up with the right Unix [...]]]></description>
			<content:encoded><![CDATA[<p>I sometimes get asked to count the number of bases with qualities greater than or equal to 20 in a quality file. I'm not entirely sure this is all that good a metric with 454 sequencing but that's another story. It always takes me a minute or two to come up with the right Unix commands to do it so I'm going to post it here so I remember (and maybe save someone else a couple minutes).</p>
<p><code>
cat *qual|grep &#039;^[^&gt;]&#039;|sed &#039;s/ /\n/g&#039;|grep -c [234][0-9]
</code></p>
<p>This is very quick and dirty (just removing lines starting with "&gt;", replacing spaces with newlines and counting the resulting lines with quals 20-40) but it seems to work ok for me. Also yes I know it's stupid to cat to a grep but I often replace the cat with head for testing. And I'm sure you could do it in a single awk or sed step but it gets done in a minute or two for several hundred million bases so I haven't really been motivated to change it.</p>
]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/biologist/counting-q20-bases-in-a-qual-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using quotation marks effectively in Unix</title>
		<link>http://scott.sherrillmix.com/blog/programmer/using-quotation-marks-effectively-in-unix/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/using-quotation-marks-effectively-in-unix/#comments</comments>
		<pubDate>Sun, 26 Nov 2006 19:00:39 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[back]]></category>
		<category><![CDATA[backtick]]></category>
		<category><![CDATA[double]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[pipe]]></category>
		<category><![CDATA[quotation marks]]></category>
		<category><![CDATA[quote]]></category>
		<category><![CDATA[single]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/using-quotation-marks-effectively-in-unix/</guid>
		<description><![CDATA[This is pretty basic knowledge but I've helped a few people out recently that had been using Unix/Linux for a while and didn't know and it sure helped me out when I figured it out. If you had asked me how many quotation marks were on a keyboard before I started doing Bash stuff I [...]]]></description>
			<content:encoded><![CDATA[<p>This is pretty basic knowledge but I've helped a few people out recently that had been using Unix/Linux for a while and didn't know and it sure helped me out when I figured it out. If you had asked me how many quotation marks were on a keyboard before I started doing Bash stuff I would have said two. But I, and it seems most non-programmers, often forget the little <code>`</code> on the same key as the tilde ~ (to the left of the numbers on standard keyboards). So there are actually three types of quotation marks and each one means something different to Unix:</p>

<dl>
<dt>Single quote/forward quote <code style="font-size:150%;font-weight: bold;">'</code></dt><dd>Just for clarity this is the key next to the Enter key on most keyboards. A pair of single quotes tells Unix that the contents are a string and that it should not mess around inside. For example: <code>x=17;echo 'This is $x';</code> will return <code>This is $x</code>. Unix did not replace the variable <code>$x</code> with 17.
</dd>
<dt>Double quote <code style="font-size:150%;font-weight: bold;">"</code></dt><dd>Double quotes again tell Unix that the contents are a string. Double quotes and the above single quotes useful for keeping Unix from messing up spaces. For example: <code>grep "To be or not to be" hamlet.txt</code> will search hamlet.txt for the famous line. In contrast, <code>grep To be or not to be hamlet.txt</code> searches for <code>To</code> in the files <code>be, or, not, to, be, hamlet.txt</code> (not what was intended). Double quotes are different from single quotes in that they allow Unix to replace variables inside them. For example: <code>x=17;echo "This is $x";</code> will return <code>This is 17</code>.</dd>
<dt>Backtick/back quote <code style="font-size:150%;font-weight: bold;">`</code></dt><dd>Just for clarity this is the key shared with ~ on most keyboards. These are really different than the other two. They tell Unix to run whatever command is inside and paste in the output. These are equivalent to using <code>$()</code>. For example: <code>echo "You are in `pwd`"</code> will return <code>You are in /usr/bin/</code> or whatever directory you are in. These can come in really handy. One common use is looping through files. Here's a slightly more complex example that uses both double and back quotes to add the filename to every row in all text files in a directory: <code>for i in `ls *.txt`;do sed "s/^/$i /" $i >$i.new;done</code></dd>
</dl> 
<p>Knowing how these are used can really help with using Unix. The difference between <code>'commands'</code> and <code>"commands"</code> is pretty subtle but can make a big difference in the results. I learned this the hard way but hopefully now you won't have to.</p>.]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/using-quotation-marks-effectively-in-unix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Reading Standard Input in a Bash Shell Script</title>
		<link>http://scott.sherrillmix.com/blog/programmer/reading-standard-input-in-a-bash-shell-script/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/reading-standard-input-in-a-bash-shell-script/#comments</comments>
		<pubDate>Sat, 08 Jul 2006 12:34:01 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[ENTER]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[standard input]]></category>
		<category><![CDATA[stdin]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/uncategorized/reading-standard-input-in-a-bash-shell-script/</guid>
		<description><![CDATA[I guess this is obvious to most people but it took me quite a while to dig it out on the internet. I wanted my bash script to be able to read from standard input like cat sourcefile.txt&#124;bash myscript.bash. It turns out the standard input can be read from /dev/stdin. So if I wanted to [...]]]></description>
			<content:encoded><![CDATA[<p>I guess this is obvious to most people but it took me quite a while to dig it out on the internet. I wanted  my bash script to be able to read from standard input like <code>cat sourcefile.txt|bash myscript.bash</code>.  It turns out the standard input can be read from <code>/dev/stdin</code>. So if I wanted to <code>sort</code> the standard input, myscript.bash would look like: <code>sort /dev/stdin</code></p>

<p>I think this is probably basic UNIX knowledge but I'm not a programmer.</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/reading-standard-input-in-a-bash-shell-script/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

