Showing posts with label Text-Processing. Show all posts
Showing posts with label Text-Processing. Show all posts

Tuesday, October 30, 2007

cowsay: a configurable talking and thinking cow

Today's Debian Package of the day Cowsay reminds me of a dull day few years back when I wrote this 'cowwords' script to amuse myself.Even a useless tool like cowsay can be interesting with creative use, CrunchBang has another cool hack using vrms and cowssay Happy Hacking! :) .

Cowsay is a useless but very fun text filter written in Perl. If you send some text into cowsay, you get an ASCII cow saying your text. For example, cowsay Hello, World! prints


_______________
< Hello, World! >
 ---------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


Script in public domain originally posted on FSUG-Bangalore Mailing-list

#!/bin/sh # # SCRIPT: cow-words.sh # AUTHOR: Rakesh 'arky' Ambati (http://www.linuxgazette.com/blog/4864) # DATE: 17 January 2005 # VERSION: you_must_be_kidding # # CREDITS: I Thank Karma_Police for the 'cow file randomizer code' # # PURPOSE: Retrieves the Dictionary.com 'Word of the Day" RSS Feed and # a random character teaches them. # # DEPENDS: 'xmlstarlet' # 'cowsay' # Both are available packages in Debian (Sid) repository. # To install them just type 'apt-get install xmlstarlet cowsay' # # # set -x # Uncomment this for debugging. # # ##################################### # Use 'cowsay -l' to the full list of cow files in your system # # (Sorry fellas I removed possible offensive 'sodomized*, head-in,telebears, # # kiss' cow files # ###################################### cows=(apt beavis.zen bong bud-frogs bunny cheese cower daemon default dragon dragon-and-cow elephant elephant-in-snake eyes flaming-sheep ghostbusters hellokitty kitty koala kosh luke-koala mech-and-cow meow milk moofasa moose mutilated ren satanic sheep skeleton small stegosaurus stimpy supermilker surgery three-eyes turkey turtle tux udder vader vader-koala www) random=RANDOM%44 ######################################### ## Get the XML feed and do the selection ## ######################################## /usr/bin/xmlstarlet sel --net -t -m "/rss/channel/item/description" -v "." "http://dictionary.reference.com/wordoftheday/wotd.rss" | /usr/bin/cowsay -n -f ${cows[random]} # End of the script

Saturday, September 29, 2007

Bash's noclobber

If there is something I don't miss is a chance of thumbing through a new book. It always seems that I never have enough money to buy them all, so the resort to the next best option. To seek out engineering students who buy books in the feverish days before the examinations only to banish them to the dark and dusty corners. Needless to say these are technical books explaining basics of languages or Unix shell environment, a particular favorite of mine.
Perhaps it is my insatiable curiosity that drives me to read all books even the 'for Dummies' books which are looked down with disdain by other geeks, I find them amusing and entertaining.

Lately I have started noticing that some information was missing here and there. For instance, the setting of no clobber of existing files is nowhere to be seen in shell books these days , I guess the authors of these technical books consider it unimportant and almost trivial.

The no clobber setting however is life saving sometimes, it prevents accidental overwriting of existing files while using IO redirection on bash shell or badly written shell scripts. It is better to set it with set -C than losing a very important file .

$ set -C # Enable it $ ls > foo bash: foo: cannot overwrite existing file $ set +C # Disable noclobber $ ls > foo # exiting file overwritten!!!

Just include a line with set -C option somewhere in .profile or .bashrc file inside your home directory.

Wednesday, September 26, 2007

Creating files the hackers way!

In *nix is all about text files, Let it be the costly piece of hardware that you brought or just some configuration setting to your favorite programs everything is humbled down to be a simple text file. Alright creating a new file doesn't necessarily mean opening your favorite editor pico or vi. There are quite faster ways for creating blank files on the shell, tell me find any simpler method. ;) Touch happens to be the standard way to create a blank file but that means I have to type five characters ( t o u c h ) being a lazy typist I use a much simpler method. $ touch testfile $ ls -l -rw-r--r-- 1 arky arky 0 Mar 23 22:31 testfile My hack is using the standard shell redirect operator > which does save some typing. ;) $ > testfile2 $ ls -l -rw-r--r-- 1 arky arky 0 Mar 23 22:31 testfile -rw-r--r-- 1 arky arky 0 Mar 23 22:31 testfile2

Popular Posts