Tuesday, April 30, 2013

Linux - Some useful applications of sed and grep

1) sed - how to find and replace within a file

This is one of the basic application of sed

sed -i 's/find-pattern/replace-pattern/g' filename



2) sed - How to search between two patterns:

sed -n '/start-pattern/,/end-pattern/p' filename

This is useful when you want to limit your search to a region within a file


e.g Between two time points

sed -n '/01:44:39/,/02:41:44/p' abc.log


3) sed - how to prefix/suffic something to the start/end of every line

You know this well if you are exposed to regular expression (makes way for some most powerful text manipulations).

^ - Denotes beginning
$ - Denotes ending

e.g Comment out some lines in a config file

sed -i 's/^/#/g' filename

e.g Add some comments to every line at the end

sed -i 's/$/<your text>/g' filename


4) grep multiple strings

grep 'warning\|error\|critical' /var/log/messages


5) grep and display few lines above the matched pattern

grep -A  2 'warning\|error\|critical' /var/log/messages


6) grep and display few lines below the matched pattern

grep -B  2 'warning\|error\|critical' /var/log/messages

Tuesday, April 16, 2013

Drive to Coonoor


Last week, we drove to Coonoor via Mysore,Gundalpet,Mudumalai National Park and Mashinagudi...Stay at YWCA Coonoor was a very pleasant experience as this holiday home was located away from the Coonoor town overlooking the nearby valley...Certainly looks like more than a century old, this colonial bungalow had the charm that is hard to find in modern hotels loaded with luxuries...I particularly liked this place for the fact that they don't (pseudo?) pamper you much as done at other places but attend to your needs in a simple manner...Most importantly, the food was prepared as per the request and served at the ground floor common hall...

We got a room at the first floor...waking up in the morning upon the chirping sound of birds and sipping the hot coffee served at the room with the view of gracious Nilgiri mountain up and the expanding valley down were joy compared to our daily rut life at Bangalore.

Drove around Coonoor and visited Dolphin's nose and Lamb's rock..Eesha had a horse ride at Dolphin's nose. After visiting Sim's park, we heeded to the suggestion of one local street side toy vendor and visited High Field tea factory to buy some spices...While we bought some spices, I must say the Green tea was bit too expensive and luckily overcame that compulsive desire to buy...Little later, bought some decent tea at a wholesale store at Coonoor town and the price was like half compared to High Field factory shop...
It was getting dark when we got there at High Field tea factory and the valley view from the shop was really stunning..Seems like it was popular shooting destination and apparently, hindi movie Raja Hindustani was shot there ;-)

Before leaving Coonoor, visited Needle Craft, an boutique selling hand embroidered linen and cotton clothes,bed sheets,cushion covers etc Rekha bought 50 gms garam masala (Rs250...it better be good..chicken would cost less than this masala)...and one frock for Eesha...Overall, it was not quite compelling buy although we bought something because of our predisposition...Nevertheless, I must say that we witnessed ourselves in a British-built Victorian villa that was tucked inside such a gorgeous surrounding...Just google Erin Villa Coonoor for pictures...

Saturday morning, we checked out and started heading back to Bangalore...Stopped at Ooty for quick snack at Virtue Bakery and some carrots and broccoli on Charring Cross...The trip was over except for the drive back home...Vacation is always shorter than you wish ;-)

Check out some of the photos @ 
Trip to Coonoor Apr 2013