Import into mysql and pipe query to file?
It might be possible to demand a constant width font and add space characters to make such a file appear as a table of sorts but editing the contents would be nearly impossible. There is a UNIX tool - entab - that does things a bit like that but it wouldn't be perfect.
BBEdit just does not support typewriter style tab stops for its windows. Sigh.
If the OP means an HTML table, that's another thing.
I use a spreadsheet for tab separated data. Comma separated is easy to convert to tabs unless there are commas in the data that need protection by escaping.
--
-> Stocks have been pelloreid <-
col1,col2,col3
xx,xxx,xxxxx
and turn it into something like:
***********************
* col1 * col2 * col3 *
***********************
* xx * xxx * xxxxx *
***********************
Readers: Switch to a constant width font in your display to see what he means.
perl has an x= operator. That's a small ASCII x that creates a string of characters x items long. It's like a += operator that adds a number to the left argument and replaces it. Page 107 in the Camel book.
$string = " ";
$string x= 5;
I would think it possible to look for regular expressions like /(\w+),/ and replace with $1 concatenated with $colwidth -len($1) spaces. In English that says search for any number of word characters followed by a comma and set variable $1 to the word characters as a string. Then add spaces as required to make up the column width and replace.
As a stand alone perl script with a while loop is ought to be fairly simple. I would probably scan the entire file as a single string variable and push results, one by one, onto a new string. You would have to scan the file first to produce a list of column widths.
Making it work as a BBEdit search and replace is another thing but it might be possible.
--
--> From the U S of A, the only socialist country that refuses to admit it. <--
On 16/06/09 at 9:51 AM +0100, Carlton Gibson <carlton...@gmail.com> wrote:
>I was thinking that some PERL script or a clever pipeline (perhaps
>using `cut` and a bit of `printf`) would do it, but I thought this
>must have been done a thousand times. I couldn't find anything on
>CPAN, but I think my problem is that (for good reason) "ASCII table"
>doesn't turn up what I'm looking for.
If you're happy with Perl, then the Text::Table module will do what you want:
<http://search.cpan.org/perldoc?Text::Table>
Charlie
--
Charlie Garrison <garr...@zeta.org.au>
PO Box 141, Windsor, NSW 2756, Australia
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt
If you're happy with Perl, then the Text::Table module will do what you want:
<http://search.cpan.org/perldoc?Text::Table>
Brilliant! Thanks.
(I knew someone had done this before.)
> I don't suppose anyone has a filter for converting (say) CSV into an
> ASCII table do they?
Nice to see some home-brewed solutions, and not all in Perl :)!
Here's a short and simple script in newLISP:
#!/usr/bin/env newlisp
(set 'file (open ((main-args) 2) "read"))
(set 'column-widths (dup 0 80))
(while (read-line file)
(push (set 'line (parse (current-line) ",")) content -1)
(unless (empty? line)
(set 'column-widths (map max (map length line) column-widths))))
(set 'format-string (join (map (fn (s) (string "%-" (inc s) "s"))
column-widths)))
(map (fn (l) (unless (empty? l) (println (format format-string l))))
content)
which turns this input:
----------------
Heading,Title,Value,Extremely Long Column,Notes
1,12312312,,1231241231231,12312
a,b,c,d,e
f,g,c,,
,,,,this is a note
----------------
into this output:
----------------
Heading Title Value Extremely Long Column Notes
1 12312312 1231241231231 12312
a b c d e
f g c
this is a note
----------------
The great thing about BBEdit's Unix filters is that you can apply them
to just the selected text...
cheers
Thanks for the reply...
I meant to take something like this:
col1,col2,col3
xx,xxx,xxxxx
and turn it into something like:
***********************
* col1 * col2 * col3 *
***********************
* xx * xxx * xxxxx *
***********************