[opensuse] converting text to table
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? Thanks, Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 2015-09-14 15:44, 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?
Libre Office / Open Office will do that. Import text into calc, and select no delimiter, but column width. Then click and resize each column in the preview, and change the type of each one if appropriate (number, date, string, or generic) if appropriate. Then, if your destination file is not LO calc, export to another format. For instance, selecting the table with the mouse and pasting into Thunderbird converts to an html table on the fly. - -- Cheers / Saludos, Carlos E. R. (from 13.1 x86_64 "Bottle" (Minas Tirith)) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iF4EAREIAAYFAlX20X0ACgkQja8UbcUWM1wsGwD/TNuxxM4HNPfAbCmZKOWsORar AIACu94ipawxTavldPkA/1fnEtRW4GYwz0WutXxpS6pxXwNqIVhuvoh4h1NFX6XV =9+1/ -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 09/14/2015 08:54 AM, Carlos E. R. wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
On 2015-09-14 15:44, 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? Libre Office / Open Office will do that.
Import text into calc, and select no delimiter, but column width. Then click and resize each column in the preview, and change the type of each one if appropriate (number, date, string, or generic) if appropriate.
Then, if your destination file is not LO calc, export to another format. For instance, selecting the table with the mouse and pasting into Thunderbird converts to an html table on the fly.
LO will export directly to HTML without any other program. But, I must warn you that the HTML is not pretty. The results look good in a browser but there's a lot of unnecessary HTML tags. -- A cat is a puzzle with no solution. Cats are tiny little women in fur coats. When you get all full of yourself try giving orders to a cat. _ _... ..._ _ _._ ._ ..... ._.. ... .._ -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
"Carlos E. R." írta:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
On 2015-09-14 15:44, 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?
Thanks for the super fast answer!
Libre Office / Open Office will do that.
Import text into calc, and select no delimiter, but column width. Then click and resize each column in the preview, and change the type of each one if appropriate (number, date, string, or generic) if appropriate.
I tried LO before but could not discover this feature own my own. For accuracy in my LO version "no delimiter" is "fixed with". Then colums can be selected in the window below as you described.
Then, if your destination file is not LO calc, export to another format. For instance, selecting the table with the mouse and pasting into Thunderbird converts to an html table on the fly.
I wanted to import it originally into LO so I don't have to export. Thanks a lot! Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 09/14/2015 03:44 PM, Istvan Gabor wrote:
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?
Sure: use cut(1) from coreutils to extract the columns specified by ranges and use an output separator between the character ranges; then use column(1) from util-linux to align the output in a table: $ cat <
12345678901234567890 hello world ! 1234567890|23456789 hello |world
Have fun, Berny -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Bernhard Voelker írta:
On 09/14/2015 03:44 PM, Istvan Gabor wrote:
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?
Sure: use cut(1) from coreutils to extract the columns specified by ranges and use an output separator between the character ranges; then use column(1) from util-linux to align the output in a table:
$ cat <
12345678901234567890 hello world ! 1234567890|23456789 hello |world
Thanks Berny, This looks very interesting and I will experiment with this approach. It is always good to know console command alternatives of what you can do with GUI programs. Thanks, Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
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
Anton Aylward írta:
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).
This is also very interesting, and I will save your answer for reference. Thanks, Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Mon, Sep 14, 2015 at 03:44:43PM +0200, 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?
to my ear it already is a table -- rows and columns in an ascii file -- what better defines a table? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (6)
-
Anton Aylward
-
Bernhard Voelker
-
Billie Walsh
-
Carlos E. R.
-
Istvan Gabor
-
toothpik