Re: A little bash/perl programming help?



On 27 Sep, 17:30, Ivan Marsh <anno...@xxxxxxx> wrote:
Okay, I admit it, I'm stumped.

I'm trying to write a script to parse out text files into 80 charter line
lengths with column numbering over each line and I just can't seem to get
the logic straight in my head. The desired output would look (something)
like:

123456789012345678901234567890123456789012345678901234567890
All work and no play makes jack a dull boy. All work and no

123456789012345678901234567
play makes jack a dull boy.

Putting each 80 character section on a separate line with the column
numbers over it.

Anyone have anything that does something like this? I was trying to write
it in bash but got more confused the more I worked on it. A perl example
would work too.

(For the record: No, it's not homework. I'm trying to write a script I
just lost when a very old server died.)

-thx

--
I told you this was going to happen.


#!/usr/bin/perl
use strict;
while(<stdin>) {
chomp;
my $line = $_;
for (my $pos =0; ;$pos+=80) {
my $chunk = substr($line, $pos, 80);
if ($chunk eq '') { last; }
for (my $i=0; $i < 80; $i++) {
print $i % 10;
}
print "\n";
print $chunk;
print "\n";
}
}

.



Relevant Pages

  • Re: A little bash/perl programming help?
    ... lengths with column numbering over each line and I just can't seem to get ... All work and no play makes jack a dull boy. ... Putting each 80 character section on a separate line with the column ... I'm trying to write a script I ...
    (alt.os.linux)
  • Re: A little bash/perl programming help?
    ... lengths with column numbering over each line and I just can't seem to get ... All work and no play makes jack a dull boy. ... I'm trying to write a script I ...
    (alt.os.linux)
  • Re: A little bash/perl programming help?
    ... lengths with column numbering over each line and I just can't seem to get ... All work and no play makes jack a dull boy. ... A perl example ... I'm trying to write a script I ...
    (alt.os.linux)
  • Re: A little bash/perl programming help?
    ... lengths with column numbering over each line and I just can't seem to get ... All work and no play makes jack a dull boy. ... I'm trying to write a script I ...
    (alt.os.linux)
  • Re: A little bash/perl programming help?
    ... line lengths with column numbering over each line and I just can't seem ... and no play makes jack a dull boy. ... Putting each 80 character section on a separate line with the column ...
    (alt.os.linux)