• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

printing a file

How do i print a C file in unix that has line numbers in it?
i want the answer right away... i think its very easy one...
1 Solution
Kim RyanIT ConsultantCommented:
You should be able to print any text file on Unix to the default printer using:

   lp file_name

Do you want the file numbers to be added by the print command, or are they alredy in your file?
cat filename | awk ´{print FNR $0}´ | lp

I looked at this on my system and it is nearly right but not quite. There may have been a typo. Also this adds nicer formatting.

cat filename | awk '{print NR ": " $0}' | lp
deep_wellAuthor Commented:
good one rbr keep it up.
Using HP-UX with HP printers there is not normally a problem
printing files with line numbers, i.e. lp filename works fine.   However,  with QMS printers I've seen them get confused in that the printer thinks the file is HPGL, but it's not and the result is no print or an error printout.  In this case, use:

lp -oPCL filename

This tells the printer to use the HP PCL language which should handle any ascii files.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now