Archive

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 Leave a comment

Sample file:

$ cat summary.txt
A|Jan|clerk|02:45
B|Jan|Salesman|02:12
C|Jan|Accountant|03:12
A|Feb|clerk|01:10
B|Feb|Salesman|11:10
B|March|Salesman|3:10
C|Feb|Accountant|3:34

Output Required:

(First field)|(last field converted to minutes)
i.e.
A|165
B|132
C|192
A|70
B|670
B|190
C|214

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 Leave a comment

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: Linux.com ]

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: ,

Fix a Frozen System with the Magic SysRq Keys

September 11, 2007 Leave a comment

You finally got your Linux environment to crash. Ctrl+Alt+Backspace does nothing, nor do the F-keys. You know you shouldn’t have installed that bad driver, but you did it anyway.

So you reach for the power button.

Stop.

Mashing in the power button to reboot could cause a problem if your hard drive is still being written to, and usually causes more problems than it solves. The Linux kernel includes a secret method of restarting your PC should it ever stop doing its job.

  1. Hold down the Alt and SysRq (Print Screen) keys.
  2. While holding those down, type the following in order. Nothing will appear to happen until the last letter is pressed: REISUB
  3. Watch your computer reboot magically.

What the individual keys do in that sequence are not as important as what it does as a whole: stops all programs, unmounts all drives, and reboots. A lot safer than just cutting the power.

Here it is again: REISUB. Remember that, as it will save you a lot of time when you are configuring a system and something gets messed up. Need a mnemonic? Try Raising Elephants Is So Utterly Boring.

As an aside, don’t try this if you just want to reboot. A normal reboot, if it can be done, should always be used instead of the REISUB keys.

R-E-I-S-U-B

Categories: Tutorial Tags:

Microsoft Unveils New Linux Hate Site

August 24, 2007 4 comments

Microsoft has finally killed off it’s old anti-Linux “Get the facts” website that had been spreading lies about Linux for years. However, don’t think that anything has changed, the site is being replaced with another, more insidious site called “Windows Server Compare.”

Windows Server Compare [ Source: ZDNet Blogs ]

Categories: Microsoft Tags:

Linux: Mac, it’s ok, we are friends.

April 2, 2007 Leave a comment

Linux runs in both PC and Mac. Advertisement video by Novell.

Categories: Uncategorized Tags: , , ,
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: