LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-25-2007, 07:47 PM   #1
tkinsella
Member
 
Registered: Dec 2005
Distribution: CentOS 6.5
Posts: 45

Rep: Reputation: 0
Question Creating a print script


I am fairly new to linux and I would like to create a script that will print a file when entered into the terminal.

ie) # pprint file
this command would print "file" to the printer specified in the script with the formating specified.
I would like the script to format the file in 2 columns, with borders and line numbers. i would like a head that specifies when the file was printed and the name of the file.

Is this possible? Does this make sense?
Thanks!!!!

tom
 
Old 12-25-2007, 08:41 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
I beleive the command-line utility enscript can do all that. See the man page for enscript for command parameters.
 
Old 12-26-2007, 12:18 PM   #3
tkinsella
Member
 
Registered: Dec 2005
Distribution: CentOS 6.5
Posts: 45

Original Poster
Rep: Reputation: 0
Hm.... enscript comes back unknown...... any other ideas? Thanks!
 
Old 12-26-2007, 01:30 PM   #4
joel2001k
Member
 
Registered: Mar 2007
Distribution: GNU/Linux debian unstable main
Posts: 95

Rep: Reputation: 17
Thumbs up perhaps a2ps

for scripting within bash look at http://www.tldp.org/LDP/abs/html/index.html

`lp` or `lpr` sends print requests to print spooler probably you want to install a2ps, ghostscript and so on, if you don't know how to write postscript

some useful commands for scripting

`head`, `tail`, `read`, `echo` ...

an example using html (for web standarts look at w3c.org), you could use xml and use `xsltproc` to convert it to html, maybe you want use redirections (pipes) - for faster execution

#!/bin/sh

file_in=()
file_out=()
file_ps=()
file_head=()
file_tail=()
wc_out=()
byte_count=()
byte_count_stop=()
current_matrix_row=()
sign0=()
sign1=()

function matrix_row{
current_matrix_row=`printf "<tr><td>%s</td><td>%s</td></tr>" $sign0 $sign1`
}

file_in=`read -p "read from file: "`
file_out=`read -p "write to file: "`
file_ps=`read -p "postscript file name: "`

file_head="<html><head></head><body><table>"

wc_out=`wc -c`
byte_count_stop=`expr match $wc_out "[0-9]*."`

[ byte_count_stop-1 ]
byte_count_stop=$?

byte_count=${wc_out:0:$byte_count_stop}

file_tail="</table></body></html>"

echo -e "$file_head\n" > $file_out

# here you may write some special code

echo -e "$file_tail\n" > $file_out

html2ps $file_out -o $file_ps
lp $file_ps

Last edited by joel2001k; 12-27-2007 at 01:03 PM.
 
Old 12-26-2007, 02:00 PM   #5
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by tkinsella View Post
this command would print "file" to the printer specified in the script with the formating specified.
I would like the script to format the file in 2 columns, with borders and line numbers. i would like a head that specifies when the file was printed and the name of the file.
Check out a2ps. If you have a postscript printer, it takes an ascii text files, generates a postscript file and sends it to the printer.

There are various options to prettify the layout, but by default it generates two column, landscape pages, with a header containing the filename, the person that printed it, the number of pages and possibly the date (can't quite remember). You can specify the --line-numbers=1 option to get it to prefix each line with its line number. See the man page for more details.

a2ps might not be installed by default, so use your package manager to add it. The same advice applies to enscript - just because it says unknown command, doesn't mean you can't add it!
 
Old 12-26-2007, 06:26 PM   #6
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.

I have used these all upon occasion, but they are rarely all installed by default ... cheers, makyo
Quote:
mpage (1) - print multiple pages per sheet on PostScript printer
a2ps (1) - format files for printing on a PostScript printer
trueprint (1) - print program listings on postscript printer.
enscript (1) - convert text files to PostScript, HTML, RTF, ANSI, and overstrikes
 
Old 12-27-2007, 04:17 AM   #7
tkinsella
Member
 
Registered: Dec 2005
Distribution: CentOS 6.5
Posts: 45

Original Poster
Rep: Reputation: 0
Thank you all soooo much! This is what I needed! Yeah, I looked at my distro CD and found the enscript stuck on there :P The way the answer was worded made me think that it is there or it isn't and I didn't know where to go. Thanks all!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Creating Script gizza23 Linux - General 4 11-27-2007 10:17 PM
[Sh script] "xpdf -cmd", How to print pdf with a script ? frenchn00b Linux - Software 1 10-02-2007 05:44 PM
Creating a script thomas289 Linux - Networking 1 12-17-2004 12:59 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM
Creating a Script? BajaNick Linux - Software 1 07-26-2003 08:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration