Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!apple!oliveb!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: transposing data {awk?} Keywords: : need to chg aabbcc to bb/cc/aa Message-ID: <5281@omepd.UUCP> Date: 28 Nov 89 18:21:11 GMT References: <4473@netcom.UUCP> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 21 In-reply-to: beaulieu@netcom.UUCP (Bob Beaulieu) In article <4473@netcom.UUCP>, beaulieu@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(" ",@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@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/