<?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-2738040487147857678</id><updated>2025-02-06T07:26:50.223-05:00</updated><category term="awk"/><category term="sed"/><category term="vim"/><category term="ab"/><category term="cat"/><category term="cut"/><category term="cvs"/><category term="date"/><category term="diff"/><category term="figlet"/><category term="find"/><category term="mkdir"/><category term="mv"/><category term="ps"/><category term="rename"/><category term="split"/><category term="ssh"/><category term="tac"/><category term="xargs"/><title type='text'>.bash_history</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.bashhistory.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2738040487147857678.post-7525562262240326033</id><published>2011-05-03T22:27:00.003-04:00</published><updated>2011-05-03T22:27:00.249-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ab"/><title type='text'>Simple web server load testing</title><content type='html'>I recently ran into &lt;u&gt;&lt;b&gt;&lt;a href=&quot;http://httpd.apache.org/docs/2.0/programs/ab.html&quot;&gt;ab&lt;/a&gt;&lt;/b&gt;&lt;/u&gt;, which is an Apache HTTP server benchmarking tool. The following is an invocation where I&#39;m running a load test on a local tomcat instance which is using 1000 requests with 10 concurrent threads.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ab -n 1000 -c 10 http://localhost:8080/test-ui/
This is ApacheBench, Version 2.3 &lt;$Revision: 655654 $&gt;
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8080

Document Path:          /test-ui/
Document Length:        7891 bytes

Concurrency Level:      10
Time taken for tests:   13.262 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      8054000 bytes
HTML transferred:       7891000 bytes
Requests per second:    75.40 [#/sec] (mean)
Time per request:       132.624 [ms] (mean)
Time per request:       13.262 [ms] (mean, across all concurrent requests)
Transfer rate:          593.05 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0      12
Processing:     5  132 349.6     28    3087
Waiting:        5  130 349.4     26    3087
Total:          5  132 349.7     28    3087

Percentage of the requests served within a certain time (ms)
  50%     28
  66%     84
  75%    145
  80%    168
  90%    264
  95%    376
  98%   1450
  99%   2412
 100%   3087 (longest request)
&lt;/pre&gt;&lt;br /&gt;
The tool has a lot of really great features and I&#39;ll try to exemplify some of them here. The following shows how you can change the User-Agent to a variant of Internet Explorer (thanks goes to &lt;a href=&quot;http://www.useragentstring.com/&quot;&gt;www.useragentstring.com&lt;/a&gt; for the value). I&#39;ve also set the verbosity level to 4 so I can verify the &#39;User-Agent&#39; value is set as intended. I&#39;ve excluded the output for brevity.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ab  -v 4 -H &quot;User-Agent: Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)&quot;   http://localhost:8080/test-ui/
&lt;/pre&gt;&lt;br /&gt;
Next is an example where I set the value of a cookie. I run into situations where I need to evaluate code for cell testing. It happens to be that our cell testing code is dependent on cookie values.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ab -n 1000 -c 10 -C &quot;cellNum=10&quot;  http://localhost:8080/test-ui/
&lt;/pre&gt;&lt;br /&gt;
The following is an example of setting the -G flag, which will output a file named &#39;perf.out&#39; which can be used with GnuPlot. The file doesn&#39;t have to be used with just GnuPlot. It can also be used with IDL, Mathematica, Igor, and Excel.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ab -n 1000 -c 10 -G perf.out http://localhost:8080/test-ui/
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/7525562262240326033/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2011/05/simple-web-server-load-testing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7525562262240326033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7525562262240326033'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2011/05/simple-web-server-load-testing.html' title='Simple web server load testing'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11850963597680846931</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3MlrZmnZtBV7T4-YH-PVZz0jtZDrdxc8FGsaJV4AD6Cg5aD-RJWYi9IxVY2DCXpX8FSAeppC1LBoSZyojG1ISGCNmZJ1sXE_ZHqINe-GGweFegkBdRE3Mc5fqQnLPMA/s220/profilepic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2738040487147857678.post-8369665329333777052</id><published>2011-04-30T23:48:00.002-04:00</published><updated>2011-05-02T14:32:19.819-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ps"/><title type='text'>Finding the memory usage of a process</title><content type='html'>I recently needed to figure out how to determine the memory usage of a process so I could log it over time. I used the following command to accomplish this. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ps -p 7557 -o pid,vsz,rss
  PID      VSZ    RSS
 7557  1983664 298536
&lt;/pre&gt;&lt;br /&gt;
You&#39;ll need to replace &#39;7557&#39; with the process id you&#39;re investigating. The meaning of &#39;VSZ&#39; and &#39;RSS&#39; is copy and pasted here from the man page:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;     rss        resident set size
     vsz        virtual size in Kbytes (alias vsize)
&lt;/pre&gt;&lt;br /&gt;
&#39;RSS&#39; represents the amount of memory resident in RAM. The rest of the memory is held in swap space or the filesystem. &#39;VSZ&#39; is the amount of virtual memory allocated to the process.</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/8369665329333777052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2011/04/finding-memory-usage-of-process.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/8369665329333777052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/8369665329333777052'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2011/04/finding-memory-usage-of-process.html' title='Finding the memory usage of a process'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11850963597680846931</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3MlrZmnZtBV7T4-YH-PVZz0jtZDrdxc8FGsaJV4AD6Cg5aD-RJWYi9IxVY2DCXpX8FSAeppC1LBoSZyojG1ISGCNmZJ1sXE_ZHqINe-GGweFegkBdRE3Mc5fqQnLPMA/s220/profilepic.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2738040487147857678.post-6742945918180710450</id><published>2011-04-26T22:58:00.000-04:00</published><updated>2011-04-26T22:58:55.235-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="mv"/><title type='text'>Moving multiple files</title><content type='html'>I recently learned that you can move multiple files in one invocation of &lt;u&gt;&lt;b&gt;mv&lt;/b&gt;&lt;/u&gt;. As long as the last argument is a directory, then all the previous files/directories will be moved into it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ mv one.txt two.txt three.txt foobar
&lt;/pre&gt;&lt;br /&gt;
If the last argument isn&#39;t a directory, then you&#39;ll see an error. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ mv one.txt two.txt three.txt 
mv: target `three.txt&#39; is not a directory
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/6742945918180710450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2011/04/moving-multiple-files.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/6742945918180710450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/6742945918180710450'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2011/04/moving-multiple-files.html' title='Moving multiple files'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11850963597680846931</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3MlrZmnZtBV7T4-YH-PVZz0jtZDrdxc8FGsaJV4AD6Cg5aD-RJWYi9IxVY2DCXpX8FSAeppC1LBoSZyojG1ISGCNmZJ1sXE_ZHqINe-GGweFegkBdRE3Mc5fqQnLPMA/s220/profilepic.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2738040487147857678.post-3010632556643101932</id><published>2011-04-05T00:09:00.000-04:00</published><updated>2011-04-05T00:09:48.219-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="date"/><title type='text'>How to convert Unix timestamps</title><content type='html'>It&#39;s been a long *time* since my last post, hence I thought I&#39;d do a post that involves time. I often run into the situation where I have a Unix timestamp and I need to determine the date. You can use the following to do this.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ date -d @1252278000
Sun Sep  6 19:00:00 EDT 2009
&lt;/pre&gt;&lt;br /&gt;
The following shows how to get the Unix timestamp for a particular moment in time.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ date -d &quot;2009-09-06 19:00:00&quot; &quot;+%s&quot;
1252278000
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/3010632556643101932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2011/04/how-to-convert-unix-timestamps.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/3010632556643101932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/3010632556643101932'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2011/04/how-to-convert-unix-timestamps.html' title='How to convert Unix timestamps'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11850963597680846931</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3MlrZmnZtBV7T4-YH-PVZz0jtZDrdxc8FGsaJV4AD6Cg5aD-RJWYi9IxVY2DCXpX8FSAeppC1LBoSZyojG1ISGCNmZJ1sXE_ZHqINe-GGweFegkBdRE3Mc5fqQnLPMA/s220/profilepic.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2738040487147857678.post-1564783520105004125</id><published>2011-01-15T16:01:00.009-05:00</published><updated>2011-01-15T22:29:59.440-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="awk"/><title type='text'>How to sum up the values in a file</title><content type='html'>Once you know &lt;a href=&quot;http://www.bashhistory.com/2010/12/how-to-remove-column-from-file.html&quot;&gt;how to remove a column from a file&lt;/a&gt;, then a time will come where you&#39;ll want to sum up the values in a column. For this example, let&#39;s take a look at a file with numbers in it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat file-with-numbers
1
2
3
4
5
6
&lt;/pre&gt;&lt;br /&gt;
We can sum up the values in this file with the following command.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat file-with-numbers | awk &#39;{sum+=$1}END{print sum}&#39;
21
&lt;/pre&gt;&lt;br /&gt;
We can see here that the sum of the numbers in the file total to 21.</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/1564783520105004125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2011/01/how-to-sum-up-values-in-file.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/1564783520105004125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/1564783520105004125'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2011/01/how-to-sum-up-values-in-file.html' title='How to sum up the values in a file'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-7822874468899751300</id><published>2011-01-13T00:31:00.001-05:00</published><updated>2011-01-13T00:52:51.584-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="rename"/><title type='text'>How to remove spaces from filenames</title><content type='html'>I often run into files with spaces in them and I want to rename them. Once again, there&#39;s a command that&#39;s appropriately named to do the job. I&#39;m going to go over how to use the &lt;u&gt;&lt;b&gt;rename&lt;/b&gt;&lt;/u&gt; command. Let&#39;s take a look at the files we&#39;re going to work with.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ls
foo bar.txt  test this.txt
&lt;/pre&gt;&lt;br /&gt;
We have two files which are named &#39;foo bar.txt&#39; and &#39;test this.txt&#39;. We&#39;re going to use the following command to get rid of the spaces.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ rename &#39;s/ /_/&#39; *.txt
&lt;/pre&gt;&lt;br /&gt;
The command takes two arguments. The first argument is a regular expression where the &#39;s&#39; stands for substitute. The contents between the first set of slashes represent what we&#39;re matching on. The &#39;_&#39; between the second set of slashes represent what we want to replace it with. The second argument, *.txt, tells &lt;b&gt;&lt;u&gt;rename&lt;/u&gt;&lt;/b&gt; what files will be affected. The preceding command happily renders the following result.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ls
foo_bar.txt  test_this.txt
&lt;/pre&gt;&lt;br /&gt;
Now let&#39;s say we want to replace the underscores with dashes. We can do this with the following command.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ rename &#39;s/_/-/&#39; *.txt
&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ls
foo-bar.txt  test-this.txt
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/7822874468899751300/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2011/01/how-to-remove-spaces-from-filenames.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7822874468899751300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7822874468899751300'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2011/01/how-to-remove-spaces-from-filenames.html' title='How to remove spaces from filenames'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11850963597680846931</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3MlrZmnZtBV7T4-YH-PVZz0jtZDrdxc8FGsaJV4AD6Cg5aD-RJWYi9IxVY2DCXpX8FSAeppC1LBoSZyojG1ISGCNmZJ1sXE_ZHqINe-GGweFegkBdRE3Mc5fqQnLPMA/s220/profilepic.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2738040487147857678.post-7492412863531189588</id><published>2011-01-03T23:57:00.000-05:00</published><updated>2011-01-03T23:57:59.443-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cvs"/><category scheme="http://www.blogger.com/atom/ns#" term="diff"/><category scheme="http://www.blogger.com/atom/ns#" term="vim"/><title type='text'>How to pipe STDOUT to vim</title><content type='html'>I usually use &lt;a href=&quot;http://colordiff.sourceforge.net/&quot;&gt;ColorDiff&lt;/a&gt; when I want to get a colorized diff from the command line. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cvs diff -up | colordiff&lt;/pre&gt;&lt;br /&gt;
I was talking with a friend about vim and he showed me how to utilize vim for a similar purpose. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cvs diff -up | vim -&lt;/pre&gt;&lt;br /&gt;
This is great because it gives you the same syntax highlighting benefits, but you don&#39;t have to install another application.</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/7492412863531189588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2011/01/how-to-pipe-stdout-to-vim.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7492412863531189588'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7492412863531189588'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2011/01/how-to-pipe-stdout-to-vim.html' title='How to pipe STDOUT to vim'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-7464948020779395832</id><published>2010-12-25T10:01:00.001-05:00</published><updated>2010-12-25T10:02:48.446-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="figlet"/><title type='text'>How to make a banner from the command line</title><content type='html'>I thought I&#39;d send out some command line Christmas cheer. What better way than to use &lt;u&gt;&lt;b&gt;figlet&lt;/b&gt;&lt;/u&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ figlet &#39;Merry XMAS!&#39;
 __  __                       __  ____  __    _    ____  _ 
|  \/  | ___ _ __ _ __ _   _  \ \/ /  \/  |  / \  / ___|| |
| |\/| |/ _ \ &#39;__| &#39;__| | | |  \  /| |\/| | / _ \ \___ \| |
| |  | |  __/ |  | |  | |_| |  /  \| |  | |/ ___ \ ___) |_|
|_|  |_|\___|_|  |_|   \__, | /_/\_\_|  |_/_/   \_\____/(_)
                       |___/                               
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/7464948020779395832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-make-banner-from-command-line.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7464948020779395832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7464948020779395832'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-make-banner-from-command-line.html' title='How to make a banner from the command line'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-2814496451539535331</id><published>2010-12-22T01:34:00.001-05:00</published><updated>2010-12-22T09:52:00.453-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cat"/><category scheme="http://www.blogger.com/atom/ns#" term="sed"/><category scheme="http://www.blogger.com/atom/ns#" term="tac"/><title type='text'>How to delete the last lines of a file</title><content type='html'>A friend of mine showed me a way to delete the last lines of a file after he read the article on &lt;a href=&quot;http://www.bashhistory.com/2010/12/how-to-delete-first-lines-of-file.html&quot;&gt;how to delete the first lines of a file&lt;/a&gt;. The following is an example of how he did this with &lt;b&gt;&lt;u&gt;sed&lt;/u&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ sed &#39;$d&#39; really_big_file.txt &amp;gt; new_file.txt&lt;/pre&gt;&lt;br /&gt;
You&#39;ll need to use the single quotes to prevent the shell, such as &lt;b&gt;&lt;u&gt;bash&lt;/u&gt;&lt;/b&gt;, from interpreting $d as a variable. The &#39;$&#39; symbol matches the last line, similar to how it matches the end of the line in a regular expression. The &#39;d&#39; tells &lt;b&gt;&lt;u&gt;sed&lt;/u&gt;&lt;/b&gt; that we want to delete the line. &lt;br /&gt;
&lt;br /&gt;
Another way to do this, albeit not as elegant, is exemplified next.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ tac really_big_file.txt | sed 1d | tac &amp;gt; new_file.txt&lt;/pre&gt;&lt;br /&gt;
If you&#39;ve never seen the &lt;b&gt;&lt;u&gt;tac&lt;/u&gt;&lt;/b&gt; command, it&#39;s similar to &lt;b&gt;&lt;u&gt;cat&lt;/u&gt;&lt;/b&gt;, but it&#39;s &lt;b&gt;&lt;u&gt;cat&lt;/u&gt;&lt;/b&gt; in reverse. I think it&#39;s kind of nifty that &lt;b&gt;&lt;u&gt;cat&lt;/u&gt;&lt;/b&gt; spelled backwards is &lt;b&gt;&lt;u&gt;tac&lt;/u&gt;&lt;/b&gt;. This helps with remembering the command.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s what I&#39;m doing in each step:&lt;br /&gt;
&lt;br /&gt;
1. &lt;b&gt;&lt;u&gt;cat&lt;/u&gt;&lt;/b&gt; the file in reverse.&lt;br /&gt;
2. Delete the first line.&lt;br /&gt;
3. &lt;b&gt;&lt;u&gt;cat&lt;/u&gt;&lt;/b&gt; the file in reverse again.&lt;br /&gt;
4. Save the output to &#39;new_file.txt&#39;.&lt;br /&gt;
&lt;br /&gt;
The end result is the same as before, but I can see someone arguing against it because of readability.</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/2814496451539535331/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-delete-last-lines-of-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/2814496451539535331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/2814496451539535331'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-delete-last-lines-of-file.html' title='How to delete the last lines of a file'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-4226644479970918238</id><published>2010-12-19T01:43:00.002-05:00</published><updated>2010-12-19T01:50:38.421-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="awk"/><category scheme="http://www.blogger.com/atom/ns#" term="find"/><category scheme="http://www.blogger.com/atom/ns#" term="xargs"/><title type='text'>How to find files larger than X</title><content type='html'>You can use the following command to find files that are larger than 50M.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ find . -type f -size +50000k
&lt;/pre&gt;&lt;br /&gt;
The -type argument tells &lt;u&gt;&lt;b&gt;find&lt;/b&gt;&lt;/u&gt; that we want to look at files and the -size argument specifies files larger than 50,000k. We can use the following command to get a nicely formatted output with the name of the file and the size.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ find . -type f -size +50000k -exec ls -lh {} \; | awk &#39;{ print $9 &quot;: &quot; $5 }&#39; 
&lt;/pre&gt;&lt;br /&gt;
Alternatively, we can do the following to get the same output.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ find . -type f -size +50000k | xargs ls -lh | awk &#39;{ print $9 &quot;: &quot; $5 }&#39; 
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;xargs&lt;/u&gt;&lt;/b&gt; is a handy command that takes each line of input and passes it to the proceeding command, which in this case is &lt;b&gt;&lt;u&gt;ls -lh&lt;/u&gt;&lt;/b&gt;.</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/4226644479970918238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-find-files-larger-than-x.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/4226644479970918238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/4226644479970918238'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-find-files-larger-than-x.html' title='How to find files larger than X'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-2103831090691573577</id><published>2010-12-17T22:14:00.000-05:00</published><updated>2010-12-17T22:14:00.348-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ssh"/><title type='text'>How to change the default ssh port</title><content type='html'>On Ubuntu, we can edit the &#39;/etc/ssh/sshd_config&#39; file to change the port our ssh server is listening on. You should find something similar to the following in this file.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;Port 22
&lt;/pre&gt;&lt;br /&gt;
You can change this value to any integer between 1025 and 65536 (inclusive). You should pick a value that won&#39;t conflict with any other services. If you want to limit ssh access to specific users, then you can add the users to the &#39;AllowUsers&#39; setting separated by spaces. Once you make the changes, you&#39;ll need to reload ssh to use the new configurations.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ sudo /etc/init.d/ssh reload
[sudo] password for mike: 
 * Reloading OpenBSD Secure Shell server&#39;s configuration sshd
   ...done.
&lt;/pre&gt;&lt;br /&gt;
You should stay logged in until you can test the configuration by logging in from a different machine. If we changed the &#39;Port&#39; value to 4200, then we can use the following command to specify  port 4200 on the remote machine for &lt;b&gt;&lt;u&gt;ssh&lt;/u&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@primus&lt;/span&gt; $ ssh -p 4200 mike@shiner
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/2103831090691573577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-change-default-ssh-port.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/2103831090691573577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/2103831090691573577'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-change-default-ssh-port.html' title='How to change the default ssh port'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-4455606340232227796</id><published>2010-12-15T21:15:00.001-05:00</published><updated>2010-12-15T21:15:00.457-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="mkdir"/><title type='text'>How to create a path of directories</title><content type='html'>I&#39;ve often times created a directory structure using a series of &lt;u&gt;&lt;b&gt;mkdir&lt;/b&gt;&lt;/u&gt; commands. For example,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ mkdir foo
&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ mkdir foo/bar
&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ mkdir foo/bar/test
&lt;/pre&gt;&lt;br /&gt;
You can create the same directory structure as above by using the -p option.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner &lt;/span&gt;$ mkdir -p foo/bar/test
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/4455606340232227796/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-create-path-of-directories.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/4455606340232227796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/4455606340232227796'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-create-path-of-directories.html' title='How to create a path of directories'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-4371783447850036697</id><published>2010-12-13T21:14:00.000-05:00</published><updated>2010-12-13T21:14:03.254-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="vim"/><title type='text'>How to execute vim commands from the command line</title><content type='html'>I was trying to execute a regular expression over multiple lines when I ran across an example of how to execute vim commands from the command line. I happen to know how to do this from inside vim, so this was a serendipitous find. First, I&#39;m going to show an example of how to do a simple replace. Here&#39;s the current contents of our test file&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat test_regex.txt
this is
a test
&lt;/pre&gt;&lt;br /&gt;
We can run the following command to replace &#39;this&#39; with &#39;there&#39;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ vim test_regex.txt -c &#39;%s/this/there/&#39; -c &#39;wq&#39;
&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat test_regex.txt
there is
a test
&lt;/pre&gt;&lt;br /&gt;
The -c arguments are executed sequentially. They&#39;re equivalent to typing : and then the contents of the argument. In the example above, we do a search/replace and then write/quit the file. If the &quot;-c &#39;wq&#39;&quot; is omitted, then vim will remain open. Now back to what I was trying to do originally.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ vim test_regex.txt -c &#39;%s/there\_.*a/regex&#39; -c &#39;wq&#39;
&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat test_regex.txt
regex test
&lt;/pre&gt;&lt;br /&gt;
The \_ tells vim that the . will include the new line character. Hence, the expression states that we want to match &#39;there&#39; and &#39;a&#39; and &lt;i&gt;&lt;b&gt;anything&lt;/b&gt;&lt;/i&gt; between these characters. This match is replaced with &#39;regex&#39;.</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/4371783447850036697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-execute-vim-commands-from.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/4371783447850036697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/4371783447850036697'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-execute-vim-commands-from.html' title='How to execute vim commands from the command line'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-4781215007055476871</id><published>2010-12-11T14:46:00.004-05:00</published><updated>2010-12-13T21:16:52.823-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="awk"/><category scheme="http://www.blogger.com/atom/ns#" term="cut"/><title type='text'>How to remove a column from a file</title><content type='html'>I often need to remove a column from a character delimited file so I can do some additional processing, such as counting up values. I&#39;m going to use a file with the following contents as an example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat name_age_city.txt
Mike|35|New York
Jason|28|Dallas
Fox|32|Washington
Mike|28|Los Angeles
Ann|23|Denver
Dana|32|Louisville
Mike|32|Atlantic City
Ryan|30|Austin
&lt;/pre&gt;&lt;br /&gt;
We can use the &lt;b&gt;&lt;u&gt;cut&lt;/u&gt;&lt;/b&gt;&amp;nbsp;command to extract the column with the age information.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat name_age_city.txt | cut -d &#39;|&#39; -f 2
35
28
32
28
23
32
32
30
&lt;/pre&gt;&lt;br /&gt;
The -d option tells &lt;b&gt;&lt;u&gt;cut&lt;/u&gt;&lt;/b&gt; that the delimiter for the columns is the &#39;|&#39; character and the -f option specifies the second column. Let&#39;s say we want to know how many people have the same age. We can use the following command to enumerate these values for us.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat name_age_city.txt | cut -d &#39;|&#39; -f 2 | sort | uniq -c
      1 23
      2 28
      1 30
      3 32
      1 35

&lt;/pre&gt;&lt;br /&gt;
If we need to extract multiple columns, &lt;b&gt;&lt;u&gt;cut&lt;/u&gt;&lt;/b&gt; gives us this functionality as well. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat name_age_city.txt | cut -d &#39;|&#39; -f 1,3
Mike|New York
Jason|Dallas
Fox|Washington
Mike|Los Angeles
Ann|Denver
Dana|Louisville
Mike|Atlantic City
Ryan|Austin
&lt;/pre&gt;&lt;br /&gt;
Unfortunately, &lt;b&gt;&lt;u&gt;cut&lt;/u&gt;&lt;/b&gt; won&#39;t allow us to reorder the columns. We get the same results if we try &quot;cut -d &#39;|&#39; -f 3,1&quot;. On a side note, we can use &lt;b&gt;&lt;u&gt;awk&lt;/u&gt;&lt;/b&gt; to give us functionality similar to &lt;b&gt;&lt;u&gt;cut&lt;/u&gt;&lt;/b&gt;. One advantage &lt;b&gt;&lt;u&gt;awk&lt;/u&gt;&lt;/b&gt; has over &lt;b&gt;&lt;u&gt;cut&lt;/u&gt;&lt;/b&gt; is the ability to reorder the columns.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ cat name_age_city.txt | awk -F &#39;|&#39; &#39;{print $3&quot;|&quot;$1}&#39;
New York|Mike
Dallas|Jason
Washington|Fox
Los Angeles|Mike
Denver|Ann
Louisville|Dana
Atlantic City|Mike
Austin|Ryan

&lt;/pre&gt;&lt;br /&gt;
The &lt;b&gt;&lt;u&gt;awk&lt;/u&gt;&lt;/b&gt; syntax requires us to put the &#39;|&#39; character in the print output to get the same behavior as &lt;b&gt;&lt;u&gt;cut&lt;/u&gt;&lt;/b&gt;.</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/4781215007055476871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-remove-column-from-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/4781215007055476871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/4781215007055476871'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-remove-column-from-file.html' title='How to remove a column from a file'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-7950911066597943170</id><published>2010-12-08T23:27:00.005-05:00</published><updated>2010-12-13T21:26:13.300-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="sed"/><title type='text'>How to delete the first lines of a file</title><content type='html'>&lt;div&gt;I had to delete the first line of a file today, but I didn&#39;t want to open the file because it was close to 1 GB in size. A file this large will make most editors pretty unhappy. Instead of opening an editor to just delete a line, I used the following handy command.&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ sed 1d really_big_file.txt &amp;gt; new_file.txt&lt;/pre&gt;&lt;br /&gt;
The &#39;1d&#39; tells &lt;u&gt;&lt;b&gt;sed&lt;/b&gt;&lt;/u&gt; that we want to delete line 1. The next command will delete the first three lines. The &#39;1,3&#39; is defining a range from line 1 to line 3. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ sed 1,3d really_big_file.txt &amp;gt; new_file.txt&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/7950911066597943170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-delete-first-lines-of-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7950911066597943170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/7950911066597943170'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-delete-first-lines-of-file.html' title='How to delete the first lines of a file'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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-2738040487147857678.post-18838692069742068</id><published>2010-12-07T00:17:00.005-05:00</published><updated>2010-12-22T01:37:43.426-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="split"/><title type='text'>How to split a file</title><content type='html'>&lt;div&gt;I often have a file that&#39;s too big. A great way to split the file is to use.....wait for it.....the &lt;b&gt;&lt;u&gt;split&lt;/u&gt;&lt;/b&gt; command. I usually split a file by line count. Here&#39;s an example invocation:&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ split -l 100 -d test_file.txt test_file_&lt;/pre&gt;&lt;br /&gt;
&lt;div&gt;The -l option defines the maximum number of lines per file. If &#39;test_file.txt&#39; has 951 lines, then we&#39;ll end up with 10 files where we have 9 with 100 lines each and 1 with 51 lines. The -d option tells split to use numeric suffixes. &#39;test_file.txt&#39; is the file we&#39;re going to split and &#39;test_file_&#39; is the prefix used for each of the files.&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;cmd-syntax&quot;&gt;&lt;span class=&quot;prompt&quot;&gt;mike@shiner&lt;/span&gt; $ ls
test_file.txt  test_file_02  test_file_05  test_file_08
test_file_00   test_file_03  test_file_06  test_file_09
test_file_01   test_file_04  test_file_07
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bashhistory.com/feeds/18838692069742068/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-split-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/18838692069742068'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2738040487147857678/posts/default/18838692069742068'/><link rel='alternate' type='text/html' href='http://www.bashhistory.com/2010/12/how-to-split-file.html' title='How to split a file'/><author><name>Mike Masters</name><uri>http://www.blogger.com/profile/11241192559845738070</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></feed>