LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-11-2011, 11:32 PM   #1
jimmyrp
LQ Newbie
 
Registered: May 2011
Posts: 9

Rep: Reputation: 0
printing from bash shell


So i have an assignment and im new to bash, and ive been on the first question worth 3% for hours. It is discouraging.

I am supposed to take some small files, and print them to a specific printer, such that the small files are concatenated into one file. The file name has to be included in the file that gets printed.

Should I be looking to concatenate the files into one file with the file names included, and then print them?

something like: -printfunction -printername < file*

I am just looking for a starting point here to help me understand and get started.
 
Old 05-11-2011, 11:44 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Here I'm assuming that the files are just plain text.

First you can concatenate the files using the 'cat' command, then you can convert the output to postscript format and send it to a printer with the 'a2ps' command.

Do some research on those two commands and try to work out how to put it all together. If you get stuck post back showing what you have tried.

Cheers,

Evo2.
 
Old 05-12-2011, 02:10 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
You may find these useful
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 05-12-2011, 05:43 AM   #4
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Here is an option.

cat file1 >> file2

then print

lp final file

Read for more details.

man lp

man lpr

Hope this helps.
 
Old 05-12-2011, 07:17 AM   #5
jimmyrp
LQ Newbie
 
Registered: May 2011
Posts: 9

Original Poster
Rep: Reputation: 0
I think I am on the right track.

If i did this: cat file1.txt file2.txt | lp -d printer

it sent one file to the printer i told it too (I think) But I don't think that the file names were included in the printout, which is what I need. I ran through the man pages for lp and lpr, and the only thing I saw that might have helped was -0 number-up=16 for lp which only put 16 files onto the page. When I tried to print using lp with this, it didn;t work (got an error).

are there any other print functions that I could take a look at that might be able to include the file names?
 
Old 05-12-2011, 08:14 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Quote:
Originally Posted by jimmyrp View Post
are there any other print functions that I could take a look at that might be able to include the file names?
Hint: you are using 'cat' as I suggested, but I also suggested another program...

Evo2.
 
Old 05-12-2011, 09:22 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
You'll find the 'echo' cmd useful for the filenames ...
 
Old 05-15-2011, 01:50 PM   #8
astromime
LQ Newbie
 
Registered: May 2011
Posts: 26

Rep: Reputation: 13
well lets just say you take two files, you can use them as arguments to a script and create a simple script to do this
Quote:
#!/bin/bash

echo $3 >> $3
cat $1 $2 >> $3
lpr $3
using the syntax "scriptname file1 file2 filetobeprinted" when using the script
 
  


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
Bash:Printing the line number in bash script suryaemlinux Programming 2 02-05-2011 10:59 AM
A question about shell (bash shell) thomas2004ch Linux - Newbie 4 08-27-2009 03:09 AM
in bash shell how to run shell script during startup rammohan04 Red Hat 2 07-31-2009 03:07 AM
copy directories and files recursively using C shell or bash shell bostonuser Programming 7 06-06-2008 02:24 AM
Printing From Da' Shell Crashed_Again Linux - General 10 01-27-2003 09:59 PM


All times are GMT -5. The time now is 04:00 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration