I've had to do something like this awhile back so here's my baby perl version. Have fun!
#!/usr/bin/perl-w use win32; use strict; # uncomment this out if you want to input the amount of chars #if($#ARGV < 0) { # die "usage: program.pl <padding chars> \n" # . "for example: program.pl 30\n" #} #my $padlength = $ARGV[0]; my $in_name=$ARGV[0]; open(FILE,"numbers.txt") || die "numbers.pl can't open file: $!"; open(OUTPUT,">numberdump.txt") or die "numbers.pl can't open file: $!" +; while (<FILE>) { chomp; # sample input: # UserID Date # 423Hm54 ATHENA02 10/1/2000 # 123456Dh60 ATHENA02 10/1/2000 # 18Dh60 ATHENA02 10/2/2000 # 10Jch6 ATHENA05 10/2/2000 # 54321Hh24 ATHENA05 10/2/2000 # 21Mwm22 ATHENA03 10/2/2000 #Look only at the summary lines where $_ == 2000 next unless ($_ =~ /2000/i); # this is to clean up the first variable length field my $padchar = "0"; my $count = length($_); my $padlength = 30; # comment this out if using ARGV $padchar = $padchar x ($padlength-$count); print $padchar, $_, "\n"; print OUTPUT $padchar, $_,"\n"; } close FILE; close OUTPUT; # sample output: # 000423Hm54 ATHENA02 10/1/2000 # 123456Dh60 ATHENA02 10/1/2000 # 000018Dh60 ATHENA02 10/2/2000 # 000010Jch6 ATHENA05 10/2/2000 # 054321Hh24 ATHENA05 10/2/2000 # 00021Mwm22 ATHENA03 10/2/2000

In reply to Re: RE: Padding out strings. by softworkz
in thread Padding out strings. by Speedfreak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.