On Wed, Jan 29, 2003 at 01:31:32PM +0000, David Cantrell wrote: > On Wed, Jan 29, 2003 at 12:49:40AM +0100, Paul Johnson wrote: > > On Tue, Jan 28, 2003 at 11:35:29PM +0000, Paul Makepeace wrote: > > > On Tue, Jan 28, 2003 at 11:22:48PM +0000, Phil Pereira wrote: > > > > Is there an easy way to split "123456" into "12-34-56"? > > > $ perl -lne 'print "$1-$2-$3" if /(\d\d)(\d\d)(\d\d)/' > > > This should start a good TIMTOWTDI thread :) > > If you insist: > > echo 123456 | perl -lne 'print join "-", /../g' > > Harrumph. Back in my day we didn't have perl, we had to chisel our > programs into lumps of coal in just the right way that the patterns > in the smoke would display the right result. We used incantations > like this: > > echo 123456 | awk 'BEGIN {FS=""} {print $1$2"-"$3$4"-"$5$6}'
Which of course rolls even neater to: echo 123456 | awk -F "" '{print $1$2"-"$3$4"-"$5$6}'; these are, of course, synonymous, but mine wins the golf prize. Setting OFS to "-" in Awk might make it possible to shrink stuff even more, but I can't be bothered. /joel