Insert FF (feed form) in text file so that when printing the printer print on a new page accordingly

Tags
file, script, solved

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
Insert FF (feed form) in text file so that when printing the printer print on a new page accordingly

Hello.
First happy new year to everybody.


I have a script that generate a text file ( /tmp/part_list.txt for example ).
This file can be edited using a kde graphical text editor like kate or kwrite
The file can be printed out from command line or within the text editor using the print option menu.



Code:

echo "" > /tmp/part_list.txt
echo "" > /tmp/part_list.txt
 
for A_DEVICE in $(lsblk --noheadings -o kname) ; do...
...
        CUR_DEVICE="$A_DEVICE"      # A_DEVICE = /dev/sda /dev/sdb /dev/sdc .....  
        gdisk -l "$CUR_DEVICE"  >>  /tmp/part_list.txt  2>&1

done

Now I would like to add the code so that when printing the file "/tmp/part_list.txt" the printer change page after each device
Something like that :



Code:

echo "" > /tmp/part_list.txtecho "" > /tmp/part_list.txt

for A_DEVICE in $(lsblk --noheadings -o kname) ; do...
...
        CUR_DEVICE="$A_DEVICE"      # A_DEVICE = /dev/sda /dev/sdb /dev/sdc .....  
        gdisk -l "$CUR_DEVICE"  >>  /tmp/part_list.txt  2>&1
        echo "some code that printer understand as do FF" >> /tmp/part_list.txt  
done

And then the file "/tmp/part_list.txt" contains some thing like :


Code:
device : /dev/sda

ligne of text
ligne of text
ligne of text
ligne of text
ligne of text
ligne of text
ligne of text
0x0c  or  do FF or .....?
device : /dev/sdb

ligne of text
ligne of text
ligne of text
ligne of text
ligne of text
ligne of text
ligne of text0x0c  or  do FF or .....?
device : /dev/sdc

ligne of text
ligne of text
ligne of text
ligne of text
ligne of text
ligne of text
ligne of text

Any help is welcome.
# 2  
Old 1 Week Ago
Notice that such a function is usually located in the printers (or, more precisely, the printer queues) backend and you are - by trying to do what you do - second-guessing the work of it. Chances are this might get filtered out in the processing the printer driver does after you send it to the queue.

Some historical background on where that mattered: you probably know that the line-feed sequence in UNIX is a "linefeed" character, whereas in DOS/Windoze it is a carriage-return plus a linefeed. The reason is: (dot-matrix) printers worked this way, the carriage-return moved the printing head back to the left side and the linefeed move the paper upwards. It was quite like the mechanical and electrical typewriters that preceeded printers. By having this sequence as a end-of-line sequence the makers of DOS could forego the necessity to write a printer driver for their OS. UNIX, on the other hand, had printer drivers and therefore didn't need a two-character sequence. Therefore it had (and has, up to this day) a one-character EOL sequence which is in turn changed to a CR+LF if you print something to one of these old dot-matrix printers with endless paper.

Now, consider what that would do to your print job if you would mess around with the EOL sequence yourself: most probably not what you wanted to have because between your artificially inserted characters and them being processed (and turned into something maybe completely different) by the driver the printer might get confused over the result.

My suggestion is: use a "high-level" document language (i.e. Postscript, TeX, PDF, ....) to create your report. You can easily force form-feeds (or, repectively, their equivalent) within these languages because the all have that. Then use a driver for the respective language (in fact there are even natively-capable Postscript printers) to process your generated file into a correct print job. This way you are save from unknown (and unwanted) side effects and furthermore you are not bound to a specific printer model. All the mentioned languages are quasi-standards and you can easily swap one i.e. Postscript-capable printer for another Postscript-capable printer and the printed result will guaranteed to look the same.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
Neo (1 Week Ago)
# 3  
Old 1 Week Ago
replace the line 'echo some code...'
with
Code:
echo -e "\f"

This User Gave Thanks to jgt For This Post:
Neo (1 Week Ago)
# 4  
Old 1 Week Ago
If somebody has a better, shorter, cleaner solution tell me.

First create a groff file

Code:
echo "" > /tmp/part_list.groff echo ".nf" >> /tmp/part_list.groff  # NO FILL MODE 
FIRST_PASS="true"

for A_DEVICE in $(lsblk --noheadings -o kname) ; do
... 
...
...
    if [[ -z $FIRST_PASS ]] ; then
           echo ".bp" >> /tmp/part_list.groff  # do a page break if not processing the first device
        else
            FIRST_PASS=""
        fi
         CUR_DEVICE="$A_DEVICE"      # A_DEVICE = /dev/sda /dev/sdb /dev/sdc .....           
         gdisk -l "$CUR_DEVICE"  >>  /tmp/part_list.groff  2>&1  

done
 #
# Finished
#
echo ".pl -3" >> /tmp/part_list.groff  # i do adjustment because groff page length does not match 
                                                 # the page length of my laser printer
                                                 # so I got to much line feed.
echo ".ex" >> /tmp/part_list.groff     # No more to do

2) Build the text file :
Code:
groff -Tascii /tmp/part_list.groff > /tmp/part_list.txt

Any comment is welcome
# 5  
Old 1 Week Ago
I'm not at all sure that I follow what you're trying to do, but if you just want to insert a formfeed character before each occurrent of a line starting with the string "device" except the first one, I would be tempted to try a simple awk script:
Code:
awk '/^device/{if(seen++) printf "\f"}1' file

or, more simply, replace your first script:
Code:
echo "" > /tmp/part_list.txt
echo "" > /tmp/part_list.txt
 
for A_DEVICE in $(lsblk --noheadings -o kname) ; do...
...
        CUR_DEVICE="$A_DEVICE"      # A_DEVICE = /dev/sda /dev/sdb /dev/sdc .....  
        gdisk -l "$CUR_DEVICE"  >>  /tmp/part_list.txt  2>&1

done

with:
Code:
device_cnt=0
 
for A_DEVICE in $(lsblk --noheadings -o kname)
do	...
	device_cnt=$((device_cnt + 1))
	if [ $device_cnt -gt 1 ]
	then	printf '\f\n'
	else	echo
	fi
	gdisk -l "$A_DEVICE" 2>&1
done > /tmp/part_list.txt

(assuming, of course, that whatever code you showed as as ... doesn't write anything to standard output).

Last edited by Don Cragun; 5 Days Ago at 08:15 AM..
This User Gave Thanks to Don Cragun For This Post:
Neo (1 Week Ago)
# 6  
Old 1 Week Ago
Thank you very much

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Print multiple copies page by page using lp command megha2525 Shell Programming and Scripting 7 04-20-2012 01:56 PM
Printer won't print but 1 page slak0 Slackware 2 04-09-2012 04:26 PM
Page Break in a file for printing koti_rama Shell Programming and Scripting 5 03-13-2012 10:19 AM
AIX Printer Issue: Blank Page Printing. sugan_p AIX 1 09-20-2011 02:04 PM
Linux to Windows Printing: PDF starts printing from middle of page. rohan69 Windows & DOS: Issues & Discussions 5 08-04-2011 06:24 AM
print formatted text to the printer tdev457 Shell Programming and Scripting 6 11-19-2010 04:32 PM
Printer delay before final form feed habler AIX 11 04-14-2010 04:12 PM
AIX printer and extra blank page after each print ITHelper AIX 6 03-29-2010 01:08 PM
line feed printing issue sherrod6970 Shell Programming and Scripting 1 10-28-2009 07:35 AM
replace last form feed with line feed prvnrk Shell Programming and Scripting 5 04-05-2009 01:59 PM
Page feed in Troff dpmore UNIX for Dummies Questions & Answers 2 05-18-2008 05:22 AM
How to insert carriage return before line feed? huey ing Shell Programming and Scripting 2 08-05-2005 02:22 PM
Disable form feed on a serial printer connected to Sco OpenServer scoman2 UNIX for Dummies Questions & Answers 0 06-28-2005 01:25 PM
Insert page breaks into .csv file welsht Shell Programming and Scripting 2 02-04-2005 02:39 PM
Form Feed... johnny_woo UNIX for Dummies Questions & Answers 5 10-31-2003 06:02 AM