Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde!uunet!wuarchive!cs.utexas.edu!sun-barr!newstop!sun!limes From: limes@sun.com (Greg Limes) Newsgroups: comp.unix.questions Subject: Re: transposing data {awk?} Message-ID: Date: 6 Dec 89 02:02:51 GMT References: <4473@netcom.UUCP> <5281@omepd.UUCP> Sender: news@sun.Eng.Sun.COM Lines: 26 In-reply-to: merlyn@iwarp.intel.com's message of 28 Nov 89 18:21:11 GMT In article <4473@netcom.UUCP>, beaulieu@netcom (Bob Beaulieu) writes: [ I am in the process of transferring data from a CPM to unix [ environ and need 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? In article <5281@omepd.UUCP> merlyn@iwarp.intel.com (Randal Schwartz) writes: > 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 How about a SED one-liner? sed 's;\(..\)\(..\)\(..\);\2/\3/\1;' Ya don't need a jackhammer when a jacknife will do ;-) -- Greg Limes [limes@eng.sun.com] Just Another UNIX Hacker -- -- Greg Limes limes@eng.sun.com ...!sun!limes 73327,2473 [choose one]