When you wish merge your Postscript files via cat command, some printers break printing after the first page. This shell script sanitize your postscript file after merge with cat command in three steps.

  • Get file header
  • Get all pages between %%Page: and %%PageTrailer
  • Add footer %%Trailer
FILEPS=file.ps
FILEMERGE=file_merge.ps
# Merge your postscript files
cat file1.ps file2.ps file3.ps > $FILEPS
 
# Sanitize your Poscript file
sed '/^%%Page:/,$d'  $FILEPS  > $FILEMERGE
awk '/%%Page:/,/%%PageTrailer/'  $FILEPS >> $FILEMERGE
echo -e '%%Trailer\n%%EOF' >> $FILEMERGE