task 3
06scp - last version (22.10.13)
# !!!---use pdf2ps only---!!!
# don't use pdftops
# it works with 1.ps !!! it must be prepared before running this program
wc -l 1.ps | sed -n 's/\([^ ]*\) .*/\1/p' > max_string_number
tail 1.ps | sed -n '/%%Pages:/p' | sed -n 's/[^0-9]*\([0-9]*\).*/\1/p' > max_page_number
#---------------------------------------------
python -c '
f=open("max_page_number")
n=int(f.read().strip()) # old number of pages (number of REAL pages)
f.close()
m=4-n%4;
if m==4: m=0 # number of additional empty pages
M=n+m # new number of pages (fictive)
K = M/8
if K*8!=M: K=K+1
L1=L2=[]
for i in range(K):
L1=L1+[M-2*i, 1+2*i, M-2*K-2*i, 1+2*K+2*i]
L2=L2+[2*K-2*i, M-2*K+1+2*i, 4*K-2*i, M-4*K+1+2*i]
if K*8!=M: L1=L1[0:4*K-2]
print "psselect -p"+str(L1)+" 1.ps|psnup -4|lp"
if K*8!=M: print "psselect -p"+str(L2[0:2])+" 1.ps|psnup -4|lp; psselect -p"+str(L2[4:4*K])+" 1.ps|psnup -4|lp"
else: print "psselect -p"+str(L2)+" 1.ps|psnup -4|lp"
f=open("max_string_number")
N=int(f.read().strip())
f.close()
N=N-10
print str(N)+",$s/%%Pages: .*/%%Pages: "+str(M)+"/"
for i in range(m): print str(N)+",$s/%%Trailer/%%Page: "+str(n+i+1)+" "+str(n+i+1)+"\\n%%Trailer/" ' > script
#--------------------------------------------
sed -n '1s/\[//;1s/, /,/g;1s/\]//p' script > 1script_for_print
sed -n '2s/\[//g;2s/, /,/g;2s/\]//gp' script > 2script_for_print
sed -i "1,2d" script
sed -i -f script 1.ps
rm script max_page_number max_string_number
Students
192.168.1.250:/Students /mnt/Students nfs noatime 1 0