Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!rpi!tale From: tale@cs.rpi.edu (Dave Lawrence) Newsgroups: comp.unix.questions Subject: Re: transposing data {awk?} Message-ID: Date: 6 Dec 89 07:09:06 GMT References: <4473@netcom.UUCP> <5281@omepd.UUCP> Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 28 In article <4473@netcom.UUCP>, beaulieu@netcom (Bob Beaulieu) writes: > 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";' In limes@sun.com (Greg Limes): > How about a SED one-liner? > sed 's;\(..\)\(..\)\(..\);\2/\3/\1;' > Ya don't need a jackhammer when a jacknife will do ;-) Only if the knife _will_do. This won't. It just transforms the first occurance of six characters on a line. The original request, as you cited, asked for field seven of the record. So, in sed: $ sed "s#\([ \t]*[^ \t]+[ \t]*[^ \t]+[ \t]*[^ \t]+[ \t]*[^ \t]+[ \t]*[^ \t]+[ \t]*[^ \t]+[ \t]*\)\(..\)\(..\)\(..\)#\1\3/\4/\2#" (Substitute hard tabs for \t if your sed doesn't comprehend that as TAB.) Yeah, sed will do the job. Sure is ugly though. Dave -- (setq mail '("tale@cs.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet"))