How to edit a pcl (binary) file ?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to edit a pcl (binary) file ?
# 1  
Old 10-25-2016
How to edit a pcl (binary) file ?

Dear Gurus,

I'm getting a bunch of print spool files in pcl format.
I need to edit them moving graphics to i.e. right to make room for barcode stickers.
I'm trying to run a script in AIX 7.1.0.0 to edit some pcl pointer positions to the right. i.e. change p1018X to p1818X.
Piece of cake.
But.
Our beloved awk, gsub, print will nicely remove also some binary x1B. Smilie
I tried :
Code:
awk '{gsub("p1018X","p1818X")} {print $0}' air01.pcl  > air02.pcl

What I get is a (useless) much smaller file:
Code:
-rw-rw----           42373 Oct 25 15:56 air01.pcl
-rw-rw-r--           27714 Oct 25 16:43 air02.pcl

I'm about to give up with Aix script for such task.
I know that dd can be used to byte editing, but I never used it.

Shall I call in a C++ programmer ?

Any idea would be greately appreciated. Thanks.
# 2  
Old 10-25-2016
The pcl format uses the escape (ascii 27) as the record separator, it is essentially a binary file. And IMO it is not something you can edit and always get decent results.

I've written simple pcl commands in C programs that do changes to a line of text - like turn on bold.

Download ghostpcl: Note they have linux executables, so you will have to run this on a linux box.
Ghostscript: GhostPCL Downloads

And see if this does what you need. The C++ coder will have to fully understand pcl code in order to make changes. Doesn't sound practical to me.
Ghostscript:ghostpcl lets you manipulate and view files.
# 3  
Old 10-25-2016
awk shouldn't be removing x1b's, but I'd definitely believe it's removing nulls.

Do you have perl?
# 4  
Old 10-25-2016
Or a binary patching with xxd ...
A little tedious, but still good to know ...

Code:
# echo "p1018X" | xxd
0000000: 7031 3031 3858 0a                        p1018X.
# echo "p1818X" | xxd
0000000: 7031 3831 3858 0a                        p1818X.

man xxd

vi -b air01.pcl :
(or :set binary if already in)
then
%!xxdLook for 7031 3031 3858 sequence and change it to 7031 3831 3858
Then change reverse
%!xxd -r
Save
:wq!
Handle it manually and become a nerd ! Smilie

Last edited by ctsgnb; 10-26-2016 at 11:59 AM..
# 5  
Old 10-26-2016
@ ctsgnb
sorry but I'm running AIX and xxd is not standard. I'm trying to keep the OS as clean as possible. Furthermore I need to automate the process.

@ Corona688
thanks. Yes I have perl. I understood that awk is a sort of shell, where gsub and print are doing the change and output. So I suppose they are the one messing things up.


I tried with tr. Nice one but it does a byte by byte replacement. I need to search for the whole string. This would be my favourite, if.....

Maybe with od? I know it is used to 'display' hex code, but I'm not sure it can be used to edit.

Another option could be dd, all examples and tutorial I found are related to changes of file blocks, filesystems etc. So I did not dare to try.

Thanks to keep searching Smilie Smilie Smilie

---------- Post updated at 04:32 PM ---------- Previous update was at 03:56 PM ----------

I don't want to be too optimistic but the following looks working:
Code:
perl -i.bak  -p -e 's/p1018X/p1818X/g;' air01.pcl

This User Gave Thanks to emare For This Post:
# 6  
Old 10-26-2016
Have you tried the same but replacing the initial string by the same string ?
And then do a binary comparison ?

Just to make sur that the file remain unchanged from a binary point of view...
# 7  
Old 10-26-2016
Perl is specifically designed to be binary-safe and have unlimited line lengths, is the thing. It's better suited to editing binary files than awk.

I bet it was the line lengths that were tripping up awk. On AIX, it'd have a maximum length of 2048 or so, and a binary file would seem to awk as a small number of gigantic lines, newlines appearing anywhere only by coincidence.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

2. Programming

Adding to a PCL file for print

I am trying to add some variable print to a list of pcl files within a folder. Am doing some programming within perl, bash and some other scripts. (Open to a format and language). I need to add an incrementing number (variable that will increment by one each time) to the first page of each pcl... (2 Replies)
Discussion started by: mach1
2 Replies

3. Shell Programming and Scripting

Adding to a PCL file for print - in a script

I am trying to add some variable print to a list of pcl files within a folder. Am doing some programming within perl, bash and some other scripts. (Open to a format and language). I need to add an incrementing number (variable that will increment by one each time) to the first page of each pcl... (1 Reply)
Discussion started by: mach1
1 Replies

4. UNIX for Dummies Questions & Answers

Create a PCL DUPLEX File using ghostscript-8.62

table.ubbfoot {background-color="#9999ff"} td.ubbfoot1 {font-size=8pt; font-family=arial,helvietica,swiss; color="#000000";} td.ubbfoot2 {font-size=8pt; font-family=arial,helvietica,swiss; color="#ffffff";} hello, i want to create PCL Duplex Output (to print) from a pdf File. i uses itanium (64)... (0 Replies)
Discussion started by: chzi
0 Replies

5. AIX

How convert PCL or PDF file to text in AIX

I need to conver a PCL or PDF file to text in AIX, and I donīt know how. (0 Replies)
Discussion started by: 10789
0 Replies

6. HP-UX

HP/Ux pcl printing

Hi, I have a pcl file with a color invoice. Can you please advise me how I can print it directly from Hp/Ux command line to a network printer with a known IP address. The printer model is Xerox Docu Color 1632. How can I configure that printer under HpUx and which command is for printing pcl... (2 Replies)
Discussion started by: piooooter
2 Replies

7. Solaris

compiled binary file gives "cannot execute binary file"

Hi, I have two Solaris machines. 1. SunOS X 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Blade-1500 2. SunOS Y 5.8 Generic_108528-13 sun4u sparc SUNW,Ultra-60 I am trying to buiild a project on both these machines. The Binary output file compiled on machine 2 runs on both the machines. Where... (0 Replies)
Discussion started by: scgupta
0 Replies

8. HP-UX

PCL question

Good People, My issue is an aging laserjet4si and its inability to interpret anything beyond PCLv2. Would anyone happen to know an easy way to force just one queue into using only PCL2 formatting? I dug around in the interface script and in model.orig but didn't see anything immmediately... (0 Replies)
Discussion started by: Eronysis
0 Replies

9. UNIX for Dummies Questions & Answers

print a file contains binary and pcl file

I have a file that contain printer escape codes and text. How can I place the image on the top of each page in that file and print that text file out with the image in Unix. Thank you. (0 Replies)
Discussion started by: caol
0 Replies
Login or Register to Ask a Question