Unix Review > Archives > 2004 > March 2004

March 2004

Shell Corner: Dateplus: Incremented, Decremented, Repeated, and Other Tools

Hosted by Ed Schaefer

This month, Bob Orlando shares his standalone "C" and awk utilities for processing and adjusting dates.

Dateplus: Incremented, Decremented, Repeated, and Other Tools
by Bob Orlando

dateplus.c
dateplus.awk

I've always been fascinated by date routines. That fascination, coupled with the frenzied push at the end of the last century to make everything Y2K-compliant, prompted me to develop some useful date routines written in "C". My objective was not to develop libraries or functions that could be easily incorporated into other "C" programs — there are plenty of "C" date libraries out there already — rather, my objective was to develop a standalone, highly portable program that returned a variety of frequently requested and adjusted dates, suitable for Bourne shell scripts.

Bourne shell scripts were my target primarily because in our shop, batch production scripts were written in Bourne. The policy was Korn for interactive use; Bourne for batch. Besides, anything written in Bourne runs in Korn shell (and practically any other shell, as well). Korn has many fine date tools and features ($SECONDS is one of which I am particularly fond for calculating process elapsed time), but those capabilities were not available to Bourne scripts. Hence, dateplus.c was Bourne born.

Date arithmetic in Unix is, at best, an inconsistent mess. There are myriad methods in Awk, Perl, TCL, etc., for manipulating time in Unix.

Sys Admin Spotlight

CMP DevNet Spotlight

Regular Expressions: Two Easy Steps Better Than One Hard One
Complicated regular expressions and yacc are powerful parsing tools, but they can cause trouble in inexperienced hands. One helpful alternative is "partial evaluation" (PE) or "active data" parsing

In the News

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 11.0

Version 11.0 delivers every issue of Sys Admin from 1992 through 2005 and every issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!




MarketPlace

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.

Six Sigma Certification
100% Online-Six Sigma Certificate from Villanova - Find Out More Now.

BugSplat - Automatic Crash Analysis
Fast online exception analysis. Capture customer crash data online.

Flowcharts from C/C++ code -- Free trial download
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.

Wanna see your ad here?