transposing data {awk?}

Randal Schwartz merlyn at iwarp.intel.com
Wed Nov 29 05:21:11 AEST 1989


In article <4473 at netcom.UUCP>, beaulieu at netcom (Bob Beaulieu) writes:
| I am in the process of t
| transferring data from a CPM to unix environ and nee to swap a data field to a
| different format. Is it possible to use awk to change the 7th field of "YYMMDD" to show "MM/DD/YY" by using the awk command?

Here's an awk one-liner:

awk '{ $7 = substr($7,3,2) "/" substr($7,5,2) "/" substr($7,1,2); print }'

Here's the equivalent in Perl (of course)...

perl -ane '$F[6] =~ s#(..)(..)(..)#$2/$3/$1#; print join(" ", at F),"\n";'

Okay, so Perl was only a few chars shorter this time. :-)

Just another Perl hacker,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/



More information about the Comp.unix.questions mailing list