Re: A little bash/perl programming help?
- From: Michael Trausch <"mike|s/\\x40/\\./g;s/|.*|/\\x40/g;|trausch"@us>
- Date: Thu, 27 Sep 2007 15:02:07 -0400
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
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
- Prev by Date: Re: A little bash/perl programming help?
- Next by Date: Re: A little bash/perl programming help?
- Previous by thread: Re: A little bash/perl programming help?
- Next by thread: Re: A little bash/perl programming help?
- Index(es):
Relevant Pages
|
|