Hi Kurt,
Here’s a record formatting question for you:
You might want to look into FormatR 
http://www.crhc.uiuc.edu/~rubel/FormatR/
Say I have a record like in this format…
nnnnnThis is a sample sentence meant to demonstrate desired word wrapping to make the appearance of a virtual column from a single long string that doesn’t have any hard returns.
… and I want to format it to look something like this:
nnnnn This is a sample sentence meant to
demonstrate desired word wrapping
to make the appearance of a virtual
column from a single long string
that doesn’t have any hard returns.
where:
- nnnnn is a 5 character string.
- is a tab character (to be replaced by three spaces).
- The first space after every 35 or so characters in the sentence (2nd field of the record) is replaced by a hard return plus eight spaces.
- The sample above is one of many records in a file, separated by a hard return.
Thanks again, friends!
-Kurt
I have two examples below, one pulls out the number and the other
doesn’t. They both give the same output. Watch out because they will
modify line, you may need a copy if you’ll want the contents later.
Enjoy,
Paul
#!/usr/bin/env ruby
require “format.rb”
include FormatR
#Have the number by itself
template1 = <<DOT
@<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
num, line1
~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
line1
DOT
#The number is in the format. As the string is left justified
the extra spaces between the number and the rest of the string get
pushed to the end and aren’t shown.
template2 =
template2.push (‘^<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<’)
template2.push (‘line2, line2’)
template2.push (‘~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<’)
template2.push (‘line2’)
f = Format.new (template1);
f2 = Format.new (template2);
num = 12345
line1 = “This is a sample sentence meant to demonstrate desired word wrapping to make the appearance of a virtual column from a single long string that doesn’t have any hard returns.”
line2 = "12345 " + line1
puts “template 1”
f.printFormat (binding)
puts “template 2”
f2.printFormat (binding)
/tmp> ./rt.rb
template 1
12345 This is a sample sentence
meant to demonstrate desired
word wrapping to make the
appearance of a virtual column
from a single long string that
doesn’t have any hard returns.
template 2
12345 This is a sample sentence
meant to demonstrate desired
word wrapping to make the
appearance of a virtual column
from a single long string that
doesn’t have any hard returns.
···
Kurt Euler keuler@portal.com wrote: