Re: A little bash/perl programming help?



Ivan Marsh, on 09/27/2007 12:30 PM said:
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 don't know how to help you in perl. However, it's pretty easy in bash
and Python. It can even be wrapped up into a slightly larger Python
program, but I figure it's quicker and easier this way.

See the attached scripts, which work in concert to do the task that I
think you're requesting.

--
Michael B. Trausch http://www.trausch.us/
Pidgin 2.2.0 and plugins for Ubuntu Feisty!
(And Thunderbird 2.0.0.6, too!) http://www.trausch.us/pidgin

Attachment: fold-with-rules.sh
Description: application/shellscript

#!/usr/bin/python

import sys

def ruler(len):
retval = ''
for i in range(len - 1):
j = i+1
retval += str(j % 10)

return retval

filename=sys.argv[1]

f = open(filename, 'rb')

for line in f:
linelen = len(line)
print ruler(linelen)
print line


Relevant Pages

  • speed problems
    ... I've become interested in Python a while ago and just converted a simple ... perl script to python. ... This was measured with a small uncompressed logfile. ...
    (comp.lang.python)
  • Re: Python vs Perl (an example)
    ... Although you point about Python being easy has some merit, ... I would not bring up an awkwadly written Perl script to back up ... sub retPrevFile ...
    (comp.lang.python)
  • Re: Choosing Perl/Python for my particular niche
    ... > Both perl and python will allow you to do this. ... > this script will read from stdin and write an uppercased version of the ... About invoking Perl as part of a simple command in a ...
    (comp.lang.perl.misc)
  • Re: Choosing Perl/Python for my particular niche
    ... > Both perl and python will allow you to do this. ... > this script will read from stdin and write an uppercased version of the ... About invoking Perl as part of a simple command in a ...
    (comp.lang.python)
  • 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)