LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 05-29-2019, 01:22 PM   #1
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
printing text from the bash shell (CLI)


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'm looking for something to let me do like this:
Code:
prompt$  cat {some file} | {some filter} {options} | lpr -
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.

Thanks in advance,
~~~ 0;-Dan
 
Old 05-29-2019, 01:29 PM   #2
WideOpenSkies
Member
 
Registered: May 2019
Location: /home/
Distribution: Arch Linux
Posts: 166

Rep: Reputation: 61
Perhaps you could try piping into zathura?
 
1 members found this post helpful.
Old 05-29-2019, 02:34 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
First, that appears to be an unnecessary use of cat.
Code:
lpr filename
will print filename See man lpr

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)
 
1 members found this post helpful.
Old 05-29-2019, 03:48 PM   #4
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771

Original Poster
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by scasey View Post
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 View Post
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:
  1. using an editor or script, make a file holding 200 lines of text. Each line is 100 characters long and ends with a newline.
  2. 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
  3. 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.
Thanks in advance,
~~~ 0;-Dan
 
Old 05-29-2019, 03:58 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
The pr command might work and it is possible to create a cups filter.
 
Old 05-29-2019, 05:17 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by SaintDanBert View Post
I would use the utility to do something like:
  1. add a few newline '\n' before any text to create a top margin
  2. add a tab '\t' or spaces ' ' at the start of each line and create a left margin
  3. add an extra newline '\n' at some character count in each line to create a right margin
  4. add a few newline '\n' or pagefeed '\f' after some line count to create a bottom margin
  5. 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

Last edited by scasey; 05-29-2019 at 05:21 PM.
 
1 members found this post helpful.
Old 07-19-2019, 11:10 AM   #7
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771

Original Poster
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by scasey View Post
...
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___.

Thanks for the reply,
~~~ 0;-Dan
 
Old 07-19-2019, 12:45 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by SaintDanBert View Post
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.)

"So I won't do it by accident."
 
1 members found this post helpful.
Old 07-19-2019, 05:53 PM   #9
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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.
 
Old 07-19-2019, 06:16 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Quote:
I thought lpr has options for margins and things.
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.
 
Old 07-23-2019, 06:25 PM   #11
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771

Original Poster
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by Shadow_7 View Post
...
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.

Thanks for writing,
~~~ 0;-Dan
 
  


Reply



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
LXer: Cli.Fyi – A Tool To Quickly Retrieve Information About eMails, IP Addresses, URLs And Lots More From The CLI Or Browser LXer Syndicated Linux News 0 03-15-2018 03:03 PM
LXer: TripleO QuickStart HA deployment of Master branch && python-openstackclient CLI ( vs Neutron CLI ) LXer Syndicated Linux News 0 02-13-2017 02:52 AM
Error: php55u-cli conflicts with php-cli-5.3.3-47.el6.x86_64 NotionCommotion Linux - Newbie 1 07-12-2016 02:02 AM
[SOLVED] Bash command to 'cut' text into another text file & modifying text. velgasius Programming 4 10-17-2011 04:55 AM
Saving CLI data in the CLI Tons of Fun Linux - General 4 04-03-2007 05:42 AM

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

All times are GMT -5. The time now is 07:38 AM.

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