Sunday, September 23, 2007

UNIX tips and tricks


Printing a line in UNIX when you know the line number using sed?
 To print line 75 from file example_file  use the following sed command.

$> sed -n 75p example_file


How to access previous (history) comands in Unix ksh?

For those wanting to access history commands on Unix somewhat similar to doskey on DOS you can set the vi as your history editor with the set command.

$> set -o vi
$>


Once done you can use the vi editing commands to access the history commands. Esc (escape) + k to access previous commands.


Getting the current working directory to show up in the prompt (ksh)?
You have to use the $PWD variable here. Add the following line in your $HOME/.profile file.
export PS1='$PWD>'


Deleting Control-M (^M) characters from a file in UNIX using vi?
In vi do run the following command
:%s/^M//g
To get the ^M hold the control key, press V then M (Both while holding the control key) and the ^M will appear. This will find all occurances and replace them with nothing.
In order to avoid the Ctrl-M characters when using ftp to transfer files from windows to UNIX use the ASCII mode.


Usage of eval
Consider:
$> list_dir=' ls -l grep "^d" '
$> $list_dir
: No such file or directorygrep: No such file or directory
"^d": No such file or directory
$> eval $list_dir
drwxr-xr-x 3 biflpu20 other 512 Feb 7 16:39 inside_nihar
The shell evaluates variables after it has looked for metacharacters like
The command $> eval $list_dir works because the line is "rescanned" by the shell.



Error handling with piped commands
The default behaviour of a UNIX piped command is to return the status of the last command in a list piped commands.
set -o pipefail

How to print a line of dashes in UNIX using the print command in ksh?

Normally when you try to print a line of dashes or any text starting with a dash e.g -3 using the 'print' command in an Unix korn shell script it will not print anything

$> print "--------------------------"

$>

To overcome this you can either use the -R option which will make print ignore all following options and escapes.

$> print -R "--------------------------"
--------------------------
$>

or use the print command with the double dash option print -- this tells the print command where -- stated that no more options follow.

$> print -- "--------------------------"
--------------------------
$>

Sunday, September 16, 2007

iMac, iPod, iPhone and i...

A lot has been written, debated, discussed some have also just cussed, but say what you want no one has been able to iGNORE Apple and its products.

As a brand it either became the "Apple of your i" or remained a "rotten apple" but Steve Jobs ensured that the apple was noticed and remains noticed ever since its comeback.

What is it about the products that get them noticed?

In my opinion it is the combination of two factors
  1. A fantastic product design.
  2. Great marketing to go with it.
In its second coming we have seen Apple come out with products that have made people desire them, want to touch them possess them, products that have the 'cool factor' products which people lust after. The products have been minimalistic in their design, simple and intuitive to use.
As any engineer will know a simple design is the most difficult to create similarly I am sure any programmer will agree that a lot of thought goes into writing code that is simple and elegant.

The products were also blessed with flashy, glamorous and rock concert like releases to match it.

Apple has been lucky to have two geniuses behind these two factors
  1. Jonathan Ive - Design Guru at apple. The person behind the iPhone, iMac and iPod.
  2. Steve Jobs - CEO Apple. The person whose keynote addresses have become major calendar events in themselves.
http://en.wikipedia.org/wiki/Jonathan_Ive
http://en.wikipedia.org/wiki/Steve_Jobs

It has been interesting watching these two people with contrasting styles, one who has kept out of the limelight preferring to work behind the scenes and the other who seems to have been born for the limelight have teamed to produce some fantastic products. The common thing linking them is that both are said to be perfectionists.

All in all looking forward to some more rabbits to be pulled out by this duo of magicians from their hats.

A TRIP TO BHANDUP PUMPING STATION - the birdwatchers paradise

"A Picture from Bhandup Pumping Station" I am a nature lover, and I often like to go birdwatching with my dad. We had read that &q...