Posts Tagged ‘*nix’

Print next few lines after pattern in AWK

May 6, 2010 Leave a comment

Input data.txt is a collection report for XYZ corp group by different collection zones.

$ cat data.txt
Total Collection = $10291 {Fri May  8}
zone7   4500
zone8   3545
zone1   1200
zone0   900
zone3   70
zone5   67
zone11  9
Total Collection = $11847 {Sat May  9}
zone1   2800
zone3   2800
zone6   2567
zone8   2300
zone9   1200
zone12  90
zone11  90

Required: We need to find out the top 4 collection zones for each day from the above file. i.e. to print next 4 lines where the pattern “Total Collection =” is found (as the items are sorted on collection amount).

This is how we can achieve this using awk:

$ awk '/^Total Collection =/{c=4;next}c-->0' data.txt
zone7   4500
zone8   3545
zone1   1200
zone0   900
zone1   2800
zone3   2800
zone6   2567
zone8   2300

Now if we need to print the header line also, something like:

$ awk '/^Total Collection =/{c=4;{print}next}c-->0' data.txt
Total Collection = $10291 {Fri May  8}
zone7   4500
zone8   3545
zone1   1200
zone0   900
Total Collection = $11847 {Sat May  9}
zone1   2800
zone3   2800
zone6   2567
zone8   2300

And if you want to just print the date part as the header with top 4 collection zones.

$ awk -F "[{,}]" '/^Total Collection =/{c=4;{print $2}next}c-->0' data.txt
Fri May  8
zone7   4500
zone8   3545
zone1   1200
zone0   900
Sat May  9
zone1   2800
zone3   2800
zone6   2567
zone8   2300
Categories: Linux / Unix, Tutorial Tags: , , ,

Multiple FS in AWK

May 6, 2010 1 comment

Sample file:

$ cat summary.txt

Output Required:

(First field)|(last field converted to minutes)

This is how we can specify two field separators (| and 🙂 with FS in awk:

$ awk 'BEGIN{FS="[|,:]"; OFS="|"} {print $1,$(NF-1)*60+$NF}' summary.txt
Categories: Linux / Unix, Tutorial Tags: , ,

Review of Ubuntu 7.10 (gutsy) new features and changes

September 27, 2007 Leave a comment

Startup and shutdown screens won’t blink any more, so no more watching of a boring black screen even for a second. Desktop theme received some minor updates: some pixels changed at the mouse cursors to make them more eye pleasant. Evolution is now displaying popup at the tray in case of a message arrival. In the file manager an image thumbnails will be automatically rotated if they were taken with a camera. Buttons of the ‘windows list’ applet in Ubuntu 7.10 will stay they original size despite a change of a window title, for example in case of web browser tab change. The very impressive Deskbar applet is initially activated. Microsoft ntfs file system support should be available for reading and writing by default (by ntfs-3g driver using FUSE). Additional set of utilities for manipulation with ntfs partitions such as format, resize, undelete and etc. is accessible via ‘ntfsprogs’ package. Read more >>

[ Source: Tolero’s tech notes ]

OSX 10.4.9 / Vista dual boot on your Windows machine

September 25, 2007 Leave a comment

This guide tells you how to install OSX 10.4.9 on your Intel or AMD Windows machine, dual booting with Vista. This guide is for information purposes only.

[ Source: Profit42 ]

Mozilla drops $3m on new company to develop Thunderbird

September 19, 2007 3 comments

Mozilla announced plans this week to sink $3 million into a new Mozilla Foundation project designed to enhance the Thunderbird mail client. Early reports indicate that the as-yet-unnamed newly formed company will focus on positioning Thunderbird for use in Internet communications, including Web-based email, IM, and SMS.

The new organization, code-named MailCo, will be headed up by longtime Mozilla community member and CTO of ActiveState, David Ascher. Along with Mozilla Foundation chair Mitchell Baker, he will lead a new development team that is “dedicated to developing, innovating, and improving Internet mail and communication software,” using Thunderbird as a starting point. Ascher acknowledges that such a project is a massive undertaking but says he is dedicated to “making email better.”

On her Mozillazine blog, Baker writes that the initial seed money will be primarily spent on building a small team for the project but additional funding is expected. The company already has a preliminary plan, however, and Baker says they center around four goals:

  • Take care of Thunderbird users.
  • Move Thunderbird forward to provide better, deeper email solutions.
  • Create a better user experience for a range of Internet communications — how does or how should email work with IM, RSS, VoIP, SMS, site-specific email, etc.
  • Spark the types of community involvement and innovation that the project has seen around Web browsing and Firefox.

[ Source: ]

Categories: Mozilla, Software Tags: , ,

Easily Install Bleeding Edge Apps with the Source-O-Matic

September 13, 2007 1 comment

Ubuntu LinuxInstall bleeding edge applications easily with Source-O-Matic, a web application that dynamically creates the file that manages what repositories you can install packages from sources.list. Besides the typical Ubuntu repositories, you can add additional repositories that make it a snap to install the newest versions of KDE, Koffice, amaroK and Wine.

[ Source: Ubuntu sources.list generator ]

Categories: Linux / Unix, Software, Tutorial Tags: ,

Wubi – The easiest way to Linux (Ubuntu)

September 12, 2007 Leave a comment

Wubi - The easiest way to Linux

Wubi is an unofficial Ubuntu installer for Windows users that will bring you into the Linux world with a single click. Wubi allows you to install and uninstall Ubuntu as any other application. If you heard about Linux and Ubuntu, if you wanted to try them but you were afraid, this is for you.

Wubi is Safe
It does not require you to modify the partitions of your PC, or to use a different bootloader.

Wubi is Simple
Just run the installer, no need to burn a CD.

Wubi is Discrete
Wubi keeps most of the files in one folder, and If you do not like, you can simply uninstall it.

Wubi is Free
Wubi (like Ubuntu) is free as in beer and as in freedom. You will get this part later on, the important thing now is that it cost absolutely nothing, it is our gift to you…

Links: Wubi, Ubuntu, How to install Wubi

Categories: Tutorial, Windows Tags: ,
%d bloggers like this: