Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can someone direct me to a utility that will let me control the formatting of raw text that I print from a bash shell terminal session? I have a batch {er, bunch} of raw text documents. The only markup consists of newlines at random line lengths and blank lines at paragraphs.
I would hope the filter let me do things like the following:
set top/bottom and left/right margins
set page size as characters per line and lines per page
set single vs. double spaced lines
wrap lines that are too long for the current margins
create page breaks based on current margins
choose among font-related options
choose portrait vs. landscape
choose 1-up vs. 2-up per sheet face
choose single vs. double sided
In ancient times, there were utilities that send escape-codes to the printers to configure one-off or persistent settings for printed text files. Hopefully, today's utility would interact with CUPS and make things happen.
I know that I could open each file with an editor or word processor and then print, but I'm hoping to automate things.
I know that I could use one of the text-to-{something else} conversion filters, but that only changes the details of the filter I'm asking about above.
First, that appears to be an unnecessary use of cat.
Code:
lpr filename
will print filename See man lpr
Thanks, I know about that. However, I want to pretti-fy the text a bit before I have 'lpr' move it to the printer queue in CUPS. Since my example said, "filter," I supplied input to the filter using 'cat'.
Quote:
Originally Posted by scasey
A brief web search* made me aware of enscript From man enscript:
Code:
enscript - convert text files to PostScript, HTML, RTF, ANSI, and overstrikes
which see. It appears to be able to both format/convert and print a text file
HTH
*I used DDG to search for "linux format print text file" (no quotes, of course)
Thanks, again, I'm also aware of 'enscript' that does all sorts of format conversions. My original post (OP) covered that, in my mind, when I said "text-to-{something else}" format conversions.
Consider the following thought experiment:
using an editor or script, make a file holding 200 lines of text. Each line is 100 characters long and ends with a newline.
use 'lpr' to print that file (Here are my results from two different HP all-in-one printers)
the lines all appear against the left edge of the paper
the lines truncate at the right edge of the paper, but some characters are partially printed
the bottom of one page and the top of the next are ragged in ways that vary based on the mechanical registration of each page as it moves through the printer
in general, significant amounts of each file are lost in poor mapping of page to paper
I would use the utility to do something like:
add a few newline '\n' before any text to create a top margin
add a tab '\t' or spaces ' ' at the start of each line and create a left margin
add an extra newline '\n' at some character count in each line to create a right margin
add a few newline '\n' or pagefeed '\f' after some line count to create a bottom margin
repeat until all text lines are output
As simple as this sounds as written, I could create such a utility. However, in the spirit of Unix™ and Linux™ I hope that there is an existing filter utility that I can install and employ and maybe enhance with my own text format preferences.
There might be another approach:
Is it possible to create a separate CUPS queue using the same printer (ie -- one printer, several queues)?
Could this separate queue have margin, sheet orientation, duplex, multi-UP, and similar settings?
In this environment, I would have a small set of queues and simply target the one with the parameter that met my needs of the moment.
add a few newline '\n' before any text to create a top margin
add a tab '\t' or spaces ' ' at the start of each line and create a left margin
add an extra newline '\n' at some character count in each line to create a right margin
add a few newline '\n' or pagefeed '\f' after some line count to create a bottom margin
repeat until all text lines are output
As simple as this sounds as written, I could create such a utility. However, in the spirit of Unix™ and Linux™ I hope that there is an existing filter utility that I can install and employ and maybe enhance with my own text format preferences.
Thanks in advance,
~~~ 0;-Dan
I've never used enscript, only read the man page. It appears to be capable of 1, 2, 3, and 4, That it, it allows the formatting of all four margins, near as I can tell. It looks like converting a file to some other format for print is optional, although I'd think that generating and printing an RTF output might fit your use case. There also appear to be highly customizable options for filtering. It appears to allow the selection of fonts and font sizes as well.
I have developed a process that creates a formatted html file from survey data contained in a database. Then I run that through html2ps and ps2pdf with appropriate configuration files, resulting in a precisely formatted PDF document to report on the results of the survey. This happens on a CentOS server. All the user has to do is download the resulting file and print it out. Had I known about enscript back then, I might have just output a text file and used the utility to create a PostScript file (which is its default)...but my process ain't broke, so I'll probably not try to fix it.
If this were my problem, I'd certainly do more research about and experimenting with this "existing filter utility" before trying to reinvent that particular wheel...but it's your call, of course
...
If this were my problem, I'd certainly do more research about and experimenting with this "existing filter utility" before trying to reinvent that particular wheel...but it's your call, of course
More research is a requirement for me as well...
One sad reality, as I see things, dictates that you first research for useful and valid names, keywords, and search terms surrounding the Linux features that you want to learn. One might spend hours looking for details about x_____, y_____, or z_____ when the rest of the world calls them a___, b___, and c___.
More research is a requirement for me as well...
One sad reality, as I see things, dictates that you first research for useful and valid names, keywords, and search terms surrounding the Linux features that you want to learn. One might spend hours looking for details about x_____, y_____, or z_____ when the rest of the world calls them a___, b___, and c___.
Thanks for the reply,
~~~ 0;-Dan
Oh, most certainly. The biggest challenge for me when adapting to UNIX was understanding and learning about all the commands, which have different names than their equivalent mainframe or DOS tools. Hanging out here helps.
One of the first questions I ask when starting in a new environment is "How do you delete a file?" The new boss said, with great concern, "Why would you ask that? You're a long way from needing to know that." (I hadn't even learned how to sign on yet...I was going to class for that the following day.)
I thought lpr has options for margins and things. I tend to use a2ps to pretty up things, but I like previewing in gimp before wasting toner/ink and paper. I know a2ps has options for formatting, like portrait/landscape, and putting more than one page on a piece of paper. Cups also has "defaults" that you can set for your printer to avoid overriding unwanted defaults.
Nope, media size, orientation, 2 sided printing and built in printer options but not anything else in the OP's list. There are many text formatting / filtering utilities but I don't know of one that does it all.
...
Cups also has "defaults" that you can set for your printer to avoid overriding unwanted defaults.
Somehow, CUPS selects a set of "filters" to convert from whichever format it gets as input into whichever format it needs for the target printer. I hope to understand this chain of filters processing someday. I'm told that I could have a set of queues in CUPS where each queue has its own parameters. The associated filters would then tilt and rotate the input into a specific format of output -- all directed to the same physical printer. Ah, heaven.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.