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.
I tried :
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.
vi -b air01.pcl :
(or :set binary if already in)
then %!xxd Look 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 !
@ 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
---------- 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:
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.
Yes, the files look unchanged from a binary point of view, same size. Also printout is OK, just the wanted changes, everything else is unchanged.
And yes, the line lenght of my file is huge. awk just goes beserk.
The challenge now is to find&edit a string with both escape char and ascii, i.e.
The [*] is to make Perl use asterisk as a literal character instead of a wildcard modifier. The second half of the expression is just taken literally anyway.
If the perl solution from Corona688 works, then use it.
Otherwise here are some alternatives, but unknown if they exist in AIX:
bbe - sed-like editor for binary files
beav - binary editor and viewer
bless - A full featured hexadecimal editor
bvi - binary file editor
dhex - ncurses based hex editor with diff mode
hexer - interactive binary editor with a Vi-like interface
jeex - visual editor to view and edit files in hexadecimal
le - Text editor with block and binary operations
lfhex - large file hex editor
ncurses-hexedit - Edit files/disks in hex, ASCII and EBCDIC
okteta - hexadecimal editor for binary files
radare2 - free and advanced command line hexadecimal editor
shed - A simple hex editor with a pico-style interface
tweak - Efficient text-mode hex editor