On Thu, Nov 29, 2001 at 11:53:38AM -0500, Johnson, Shaunn wrote: > [sample] > > 2001q2 06 P92786 IEMMM01 1 6 > 2001q2 06 P92786 IEMMM01 1 8 > 2001q2 06 P56576 IEMFF01 1 23 > > [result] > > 2001q2 06 P92786 IEMMM01 1 06 > 2001q2 06 P92786 IEMMM01 1 08 > 2001q2 06 P56576 IEMFF01 1 23
OK. > Between the fields are spaces AND tabs. I thought I'd > have to figure out how to split the file, make an array > out of each column and then rewrite / edit into the same > file. > > I think it should be easy if I do something like: > > $vals[5] =~ s/(\w+)/(0$1)/g; You're doing too much work. The last field in this series of columns is a number, and you want to display that as a 2-digit quantity (with leading zero). No need to split out the columns only to rebuild them again, since you're looking for the *last* column in the file. The trick is to use sprintf (that's why it's there), and the /e modifier in your regex. Here's a sample solution: #!/usr/bin/perl -w use strict; while (<DATA>) { s/(\d+)$/sprintf("%02d", $1)/e; print; } __DATA__ 2001q2 06 P92786 IEMMM01 1 6 2001q2 06 P92786 IEMMM01 1 8 2001q2 06 P56576 IEMFF01 1 23 Z. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]