Format problems with fields

The following output has a space as the Field Separator.

I need:

$1 Set the field width to 15 then zero-fill to the right.
$6 Set the field width to 15 then zero-fill to the left.

01-10016 1000 MV010 20090708 12003 $NK0015101 01
01-100161 12000 MV070 20090708 12003 $NK0015201 01
01-100162 10000 MV010 20090708 12003 $NK0015301 01
01-100163 200 MV010 20090708 12003 $NK0015401 01
01-100165 1200 MV003 20090708 12003 $NK0015501 01

Both fields in the input file are strings.

Thanks,
Pawee

'zero-fill' or 'pad-with-spaces'?

Sorry for the mixup.
I meant Pad with zeros :wink:

Hope it's clearer

You can try something like this:

awk 'BEGIN{z="0000000000"}{
  $1=$1 substr(z,1,15-length($1))
  $6=substr(z,1,15-length($6)) $6
}1' file

Regards

Hi,

Not quite there.

I'm getting an error:

awk: Syntax error near line 4
awk: bailing out near line 4

Regards,

Try it with nawk or /usr/xpg4/bin/awk on Solaris.

Regards

Hi,

Much Regards and really appreciated.

Nawk worked it out:b:

Ahsante Sana - That's, Thank You Very Much in Swahili...!