![](https://seccdn.libravatar.org/avatar/cabdbf4d350ab6a15265803acab1634d.jpg?s=120&d=mm&r=g)
On 09/14/2015 09:44 AM, Istvan Gabor wrote:
Hello:
I would lie to convert a simple ascii or utf8 encoded textfile to a table. The text has no delimiters between columns, but each column in the text file has its specific character lenght. For example in each row of the text characters 1-10 should go into column 1, characters 12-19 into column 2 etc. Is this possible, how?
Gee WOW. This is an old UNIX V7 CLI problem. UNIX of that era was all about streaming text problems like this. Often reformatting "card data" or the stuff from mainframes that was deliberately 'packed'. Yes you could do it with perl or awk. I'd use perl these days. I seem to recall one of the O'Reilly books on perl actually having an example of this, although it was unpacking a TCP header. Look at the 'unpack' function. There's also a CPAN module to give extra 'strength & capability'. <quote> You cant use split because the fields have no distinct separator. Instead, fields are determined by the byte offset in the record. </quote> Something like $field1 = unpack("c10", $inputstring); or possibly ($field1, $field2) = unpack("c10c10", $inputstring); But do experiment! http://docstore.mik.ua/orelly/perl/learn/ch16_02.htm http://perldoc.perl.org/perlpacktut.html#String-Lengths What do you mean by a 'table'? Are you trying to generate HTML code? But back in the 1970s I would have done this with CUT(1) and PASTE(1). -- A: Yes. > Q: Are you sure? >> A: Because it reverses the logical flow of conversation. >>> Q: Why is top posting frowned upon? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org