Error 

Archive for August, 2008

Extracting text segments with sed

Posted August 30, 2008 at 11:08pm in Computers

A couple days ago a friend sent an email to a mailing list I am on wondering how to replace the first 99 characters of a line and extracting characters 100-106 inclusive.

cat file | sed 's/^.\{99\}\(.\{7\}\).*/\1/g'

I will let you look up the regex to know what each part is doing. You would need to do this on a per line basis if you wanted to get 100-106 from each line.

Update: I realize that this is somewhat poor design since I don’t need to cat the file to sed, sed will handle reading from the file.  I was just showing that the output needed to be sent to sed for the purpose my friend was looking for.  In a real app that needed the functionality you would process the file line by line and pass that line to the sed command to grab the 7 characters.

Using stdin as an input file

Posted August 26, 2008 at 09:08pm in Computers

This is just a quick example I whipped up, it isn’t an actual situation where you might use it and wget might even take stdin for urls.

Lets say you have a html file you want to download all of the mp3s from so you run the following command to get the urls

[21:41:33][user@host ~]$ cat index.html | sed -e 's/"/\n/g' | egrep '^http.*\.mp3$'
http://www.greatestsiteever.com/song.mp3
http://www.goodmusic.com/goody.mp3
http://www.badmusic.com/bad.mp3
...

The thing is that you don’t want to write those urls to a file on the drive because you just don’t want the clutter.

Enter /dev/stdin

[21:45:48][user@host ~]$ cat index.html | sed -e 's/"/\n/g' | egrep '^http.*\.mp3$' | wget -i /dev/stdin
--21:45:49--  http://www.greatestsiteever.com/song.mp3
Resolving www.greatestsiteever.com... 10.10.10.1
Connecting to www.greatestsiteever.com|10.10.10.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `song.mp3'

    [   <=========================================================>   ] 3,443,012      1832.5K/s   in 2.2s   

21:45:51 (1832.5 KB/s) - `song.mp3' saved [43012]

FINISHED --21:45:51--
Downloaded: 1 files, 3.28M in 2.2s (1832.5 KB/s)
......

This technique can be very handy depending on the type of work you are doing. If you are needing to pass a configuration file to an application and the filesystem is read only or you don’t want to actually write the config to the filesystem or any situation where a command needs an input file and you don’t want to create any files.

Delayed Updates on Job… Mac… etc

Posted August 6, 2008 at 10:08pm in Life

First off I apologize to those who actually read my blog, I have been busy with work and have had very little to write about.

On July 21st my contract position at Google ended and my position as a fulltime Googler started.  With that came a new Macbook Pro, my first experience using a Mac.  For a long time I have had this view of Macs that the applications lacked a lot of options and most Mac users just wanted simple point and click and were willing to give up some funtionality.  I think Kevin Rose put it best when he said that Apple has picked X number of priorities with each OS X release and they do each of them very well.  Unlike Microsoft who choosed X*4 number of features and none of them are done as well as they could be.

Since getting my Mac I have absolutely loved the experience.  There have been some headaches.  One being the lack of home and end keys and that the combination of keys change in applications, but if you can adapt quickly it doesn’t really pose much of a problem.  The other thing was quiting applications, I always knew that command+Q would quit, but I am so used to WIndows/Linux that I was still in the mode of just clicking the X.  I sometimes miss being able to maximize a window with a mouse click, but I have gotten used to always leaving some space on the sides of my applications.  It really only took me a day or two of using it on a regular basis to get past these annoyances (if you can call them that).

This last weekend was tax-free weekend in GA so I grabbed a 22″ HP LCD.  I now wish I had grabbed the 24″, but I may go back in a week or two (when I have to pay tax grr) and grab it.  The glossy screen is really nice, if I had more lights on or had a window behind my desk it might be a big problem, but with my setup it is awesome.

I recently bought Ooma, which put simply is instant VOIP. You pay $250 for the hub and a scout and you just plug it into the network, activate and start calling. No monthly fees. You do have the option to pay $99/yr (8.25/mo) to have instant 2nd line, and some other features. One thing that can be a draw back is that it uses peer to peer connectivity to handle call bandwidth or something like that, so by paying for premiere you bypass that and go straight through their servers. All calls are supposed to be encrypted I believe, but I don’t really talk about anything that important on the phone.

I am going to try to keep this updated more often, sometimes it is hard to think of anything worthy of posting.