transposing data {awk?}
Greg Limes
limes at sun.com
Wed Dec 6 13:02:51 AEST 1989
In article <4473 at netcom.UUCP>, beaulieu at 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 at omepd.UUCP> merlyn at 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(" ", 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
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 at eng.sun.com]
Just Another UNIX Hacker
--
-- Greg Limes limes at eng.sun.com ...!sun!limes 73327,2473 [choose one]
More information about the Comp.unix.questions
mailing list