Operating System - HP-UX
1848214 Members
5927 Online
104022 Solutions
New Discussion

lp printing depending on line length

 
eric stewart
Frequent Advisor

lp printing depending on line length

If I want to use different printer classes via an option to the lp command depending on the line length of the file to be printed. What would the easiest way to determine the maximum line length of the file to be printed?
If the line length < 80 I want to print portrait. If the line length < 132 but > 80, I wnat to print landscape. If the line length > 132 I want to use a different printer option.
I know I can write an awk script to print the max length. Any other suggestions?
TIA
Good help is easy to find within forums
4 REPLIES 4
Rick Garland
Honored Contributor

Re: lp printing depending on line length

There is the 'wc' command as well.
Alan Riggs
Honored Contributor

Re: lp printing depending on line length

You could do something like:

if [ `cut -c 80- ` ]
then
if [ `cut -c 128- ` ]
then
lp -d LINEPRINTER
else
lp -d LANDSCAPE
fi
else
lp -d PORTRAIT
fi

But doing it with awk is more elegant.
Tommy Palo
Trusted Contributor

Re: lp printing depending on line length

You could also use "fold" maybe in combination with "wc", but still the easiest is awk.

wc vs. fold | wc
awk 'length > 80'
Keep it simple
Dan Hetzel
Honored Contributor

Re: lp printing depending on line length

Hi Eric,


As 'wc' won't report the longest line length,
'awk' would be a lot more practical to use.
You can use 'fold' as well to fold your lines so that they will fit on your printed document.

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com