Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #5371 > unrolled thread

convert text mit tab stops to table

Started byekkardgerlach <egerlach@aiai.de>
First post2012-05-21 12:52 +0200
Last post2012-05-23 14:21 +0200
Articles 9 — 5 participants

Back to article view | Back to comp.os.linux.misc


Contents

  convert text mit tab stops to table ekkardgerlach <egerlach@aiai.de> - 2012-05-21 12:52 +0200
    Re: convert text with tab stops to table ekkardgerlach <egerlach@aiai.de> - 2012-05-21 12:54 +0200
    Re: convert text mit tab stops to table Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-05-21 14:05 +0200
    Re: convert text mit tab stops to table The Natural Philosopher <tnp@invalid.invalid> - 2012-05-21 13:14 +0100
    Re: convert text mit tab stops to table David Brown <david@westcontrol.removethisbit.com> - 2012-05-21 15:03 +0200
    Re: convert text mit tab stops to table "Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at> - 2012-05-22 11:46 +0000
      Re: convert text mit tab stops to table ekkardgerlach <egerlach@aiai.de> - 2012-05-23 10:50 +0200
        Re: convert text mit tab stops to table Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-05-23 12:48 +0200
          Re: convert text mit tab stops to table ekkardgerlach <egerlach@aiai.de> - 2012-05-23 14:21 +0200

#5371 — convert text mit tab stops to table

Fromekkardgerlach <egerlach@aiai.de>
Date2012-05-21 12:52 +0200
Subjectconvert text mit tab stops to table
Message-ID<a1ul3cF3b9U1@mid.individual.net>
Hi,
any tool available to convert a ascii-text with tab stops to a table
according to tabs?

a2ps considers tab stops but squeezes two short text sections with two
tabs to  *one* column. I need a strict a conversion to a table where any
tab stop starts a new column.

The aim is a postscript file that is printable.

tia
Ekkard

[toc] | [next] | [standalone]


#5372 — Re: convert text with tab stops to table

Fromekkardgerlach <egerlach@aiai.de>
Date2012-05-21 12:54 +0200
SubjectRe: convert text with tab stops to table
Message-ID<a1ul70F3b9U2@mid.individual.net>
In reply to#5371
correction: *with* tab stops

i wrote:

> Hi,
> any tool available to convert a ascii-text with tab stops to a table
> according to tabs?
> 
> a2ps considers tab stops but squeezes two short text sections with two
> tabs to  *one* column. I need a strict a conversion to a table where any
> tab stop starts a new column.
> 
> The aim is a postscript file that is printable.
> 
> tia
> Ekkard

[toc] | [prev] | [next] | [standalone]


#5375

FromJanis Papanagnou <janis_papanagnou@hotmail.com>
Date2012-05-21 14:05 +0200
Message-ID<jpdb2s$f3u$1@speranza.aioe.org>
In reply to#5371
Am 21.05.2012 12:52, schrieb ekkardgerlach:
> Hi,
> any tool available to convert a ascii-text with tab stops to a table
> according to tabs?
>
> a2ps considers tab stops but squeezes two short text sections with two
> tabs to  *one* column. I need a strict a conversion to a table where any
> tab stop starts a new column.
>
> The aim is a postscript file that is printable.

I'd use tbl/groff.

Janis

[toc] | [prev] | [next] | [standalone]


#5376

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2012-05-21 13:14 +0100
Message-ID<jpdbk1$pt4$1@news.albasani.net>
In reply to#5371
ekkardgerlach wrote:
> Hi,
> any tool available to convert a ascii-text with tab stops to a table
> according to tabs?
> 

cc ? :-)

Seriously there is a free PDF library - PDFlibLite - that will in 
principle work if you parse the stuff you want using a language like C 
or PHP and then you can write functions to place simple text anywhere 
you want.

I have used it to formulate invoices and the like. Its limited, but its 
solid in what it can do.

http://www.pdflib.com/download/pdflib-family/pdflib-lite-7/


> a2ps considers tab stops but squeezes two short text sections with two
> tabs to  *one* column. I need a strict a conversion to a table where any
> tab stop starts a new column.
> 
> The aim is a postscript file that is printable.
> 

yep. been there done that got the T-shirt.

I have a few bits of php library that work up a slightly better 
interface to the Lite library than are supplied.

Its a few days work to do what you want: also you are probably 
restricted to inbuilt PDF fonts ..I cant remember..anyway I used 
helvetica throughout.

Tools are provided to decide the size of strings that you want to print 
so you can do wrapped columns, text centering.right justification and 
the like..but it all gets a bit fraught.


If its any use, heres a waste of bandwidth...

<?php
// Here we go then. Simple functions to  set up text an images into PDF 
format.
// Probably worth having some global variables../

$font=0; //current font handle
$fontstyle="normal";
$fontpoint=10;
$pdf=""; // the current resource.

function setfont($size,$weight)
{
	global $fontpoint;
	$fontpoint=$size;
	global $fontstyle;
	global $font;
	global $pdf;
	if ($fontstyle!=$weight)
		{
		if ($weight=='normal')
			$font=pdf_load_font($pdf,"Helvetica","iso8859-1","");
		else if ($weight=='bold')
			$font=pdf_load_font($pdf,"Helvetica-Bold","iso8859-1","");
		else if ($weight=='italic')
			$font=pdf_load_font($pdf,"Helvetica-Oblique","iso8859-1","");	
		else if ($weight=='bold-italic')
			$font=pdf_load_font($pdf,"Helvetica-BoldOblique","iso8859-1","");
		$fontstyle=$weight;
		}
pdf_setfont($pdf,$font,$fontpoint);
}

function end_page()
	{
	global $pdf;
	PDF_end_page($pdf);
	}
function close_document()
	{
	global $pdf;
	pdf_close($pdf);
	}
function new_page($title)
	{
	global $font,$fontweight,$fontstyle,$fontpoint,$pdf;
	pdf_begin_page($pdf,595,842);
	box(15,750,565,50,"#D0D0D0",0);
	setfont(14,'bold');
	$img=pdf_load_image($pdf,"gif","../Images/Logo2.gif","" );
	pdf_place_image($pdf,$img,25,777,0.10);
	text(297.5,760,$title,'centre');
	setfont(8,'normal');
	date_default_timezone_set ("Europe/London");
	text(470,790,date("G:i T: D M d Y"),'left');
	}
function new_document()
	{
	global $pdf;
	$pdf=PDF_new();
	pdf_begin_document($pdf,"","compatibility=1.5");
	}

function text($x,$y,$text,$align)
	{
	global $pdf,$font,$fontpoint;
	pdf_setfont($pdf,$font,$fontpoint);
	 // $text=mb_convert_encoding($text, "ISO-8859-1","UTF-8");
	if($align=='right')
		$x-=pdf_stringwidth($pdf,$text,$font,$fontpoint);
	else if ($align=='centre')
		$x-=pdf_stringwidth($pdf,$text,$font,$fontpoint)/2;
	pdf_show_xy($pdf,$text,$x,$y);
	return pdf_stringwidth($pdf,$text,$font,$fontpoint);
	}

function box($x,$y,$width,$height,$color) // color is #XXXXXX
	{
	global $pdf;
	setcolor($color);
	pdf_rect($pdf,$x,$y,$width,$height);
	pdf_fill($pdf);
	setcolor("#000000"); // back to black.
	}
function setcolor($color)
	{
	global $pdf;
	$string = str_replace("#","",$color);
	$red = hexdec(substr($string,0,2)) / 255;
	$green = hexdec(substr($string,2,2)) / 255;
	$blue = hexdec(substr($string,4,2)) / 255;
	pdf_setcolor($pdf,"fill",'rgb', $red, $green, $blue,0);
	}
function send_pdf_file($name)
	{
	global $pdf;
	 $buf = PDF_get_buffer($pdf);
      $len = strlen($buf);
      header("Content-type: application/pdf");
      header("Content-Length: $len");
      header("Content-Disposition: inline; filename=\"".$name.".pdf\"");
      print $buf;
	}
function print_pdf_file($printer)
	{
	global $pdf;
	$buf = PDF_get_buffer($pdf);	
	$len=strlen($buf);
	$handle=popen("/usr/bin/lp -o sides=one-sided -d ".$printer." -- -", 'w');
	fwrite($handle,$buf);
	}
	
function mail_pdf_file($email, $subject,$from,$return_path,$body,$filename)
{
	global $pdf;
	$buf=PDF_get_buffer($pdf);
	$attach=chunk_split( base64_encode($buf),72, "\n");
	$boundary = md5( time() );
	$headers = sprintf("From: %s\nMIME-Version: 1.0\nContent-Type: 
multipart/mixed; boundary=\"%s\"",
				$from, $boundary);
	 $message = sprintf("\nThis is a multi-part message in MIME 
format.\n--%s\nContent-Type: text/plain; charset=UTF-8; 
format=flowed\nContent-Transfer-Encoding: 
7bit\n\n%s\n\n--%s\nContent-Type: application/pdf; 
name=\"%s\"\nContent-Disposition: inline; 
filename=\"%s\"\nContent-Transfer-Encoding: base64\n\n%s\n\n--%s--\n",
      $boundary,$body,$boundary,$filename, $filename,$attach,$boundary);
      mail($email, $subject, $message, $headers, "-f ".$return_path );
     }
?>


> tia
> Ekkard


-- 
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

[toc] | [prev] | [next] | [standalone]


#5378

FromDavid Brown <david@westcontrol.removethisbit.com>
Date2012-05-21 15:03 +0200
Message-ID<KdidnV3A3P4poCfSnZ2dnUVZ7qKdnZ2d@lyse.net>
In reply to#5371
On 21/05/2012 12:52, ekkardgerlach wrote:
> Hi,
> any tool available to convert a ascii-text with tab stops to a table
> according to tabs?
>
> a2ps considers tab stops but squeezes two short text sections with two
> tabs to  *one* column. I need a strict a conversion to a table where any
> tab stop starts a new column.
>
> The aim is a postscript file that is printable.
>
> tia
> Ekkard

If it's a one-off, then use LibreOffice/OpenOffice.

[toc] | [prev] | [next] | [standalone]


#5398

From"Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at>
Date2012-05-22 11:46 +0000
Message-ID<dce018994c3c2fe51bc813e789e9191f@remailer.privacy.at>
In reply to#5371
ekkardgerlach <egerl...@aiai.de> [e]:
e> any tool available to convert a ascii-text with tab stops to
e> a table according to tabs?

tabfmt (format tabular data) by Claudio Jolowicz, or rs (reshape a
data array, a BSD command ported to linux) might be useful to you.

[toc] | [prev] | [next] | [standalone]


#5404

Fromekkardgerlach <egerlach@aiai.de>
Date2012-05-23 10:50 +0200
Message-ID<a23mn7FghoU1@mid.individual.net>
In reply to#5398
thx to all!
from suse-mailinglist I got the best solution: "column" included in
util-linux:

cat lab2.txt  | tr "\t" ";" | column -t -s ";"

change tab to ; because column doesn't like tabs, then column. Great!

Ekkard

[toc] | [prev] | [next] | [standalone]


#5405

FromJanis Papanagnou <janis_papanagnou@hotmail.com>
Date2012-05-23 12:48 +0200
Message-ID<jpif9h$dab$1@speranza.aioe.org>
In reply to#5404
Am 23.05.2012 10:50, schrieb ekkardgerlach:
> thx to all!
> from suse-mailinglist I got the best solution: "column" included in
> util-linux:
>
> cat lab2.txt  | tr "\t" ";" | column -t -s ";"

(This is an "Useless Use Of Cat".)

>
> change tab to ; because column doesn't like tabs, then column. Great!

This is not true. (Column just doesn't handles multiple TABs the
way you seem to like it.)

Column also doesn't create postscript, as you initially asked for.

See also the pr(1) command that you find on Unix systems, any which
handles the TABs the way you like.

And mind also that column is non-standard (while pr is standard).

Janis

>
> Ekkard

[toc] | [prev] | [next] | [standalone]


#5406

Fromekkardgerlach <egerlach@aiai.de>
Date2012-05-23 14:21 +0200
Message-ID<a2432lFcjiU1@mid.individual.net>
In reply to#5405
Am 23.05.2012 12:48, schrieb Janis Papanagnou:

> Column also doesn't create postscript, as you initially asked for.
I want to convert the text-file with columns to a postscript AFTER.

> See also the pr(1) command that you find on Unix systems, any which
> handles the TABs the way you like.
> 
> And mind also that column is non-standard (while pr is standard).
thx
But pr is very complicated, nearly no examples available.

# pr -e25 <lab2.txt
.. squeezes two small columns to ONE column if -e is set to 20 or less.
With -e set to 25 *all* colums are 25 chars wide. So it's not usable for
me, "column" from util-linux is intelligent and expands a column only as
far as it is needed. :)

A nice feature of pr would be  --sep-string  but
   # pr -e25 --sep-string="|" <lab2.txt
has no effect. A bug? :(

Ekkard

[toc] | [prev] | [standalone]


Back to top | Article view | comp.os.linux.misc


csiph-web