Question & Answer
Question
How do I programatically remove bytes from the start or end of a file?
Answer
To programatically remove bytes from either the start or end of a file, you can use the built in linux command, dd.
The command syntax description follows:
dd if=<infile> -of=<outfile> -bs=<X> -skip=<Y> -count=<Z>
where <infile> represents the original file to be read
<outfile> represents the name of the file to be produced by running the dd command
<X> represents the byte size or count.
<Y> represents the number of X to skip at the front of the file
<Z> represents the number of <X> units to keep
For example,
dd -if /nz/kit/log/postgres/pg.log -of /nz/kit/log/postgres/pg.log.reduced -bs 100 -count 5
will read the /nz/kit/log/postgres/pg.log file and keep the first 500 bytes and redirect these bytes to the /nz/kit/log/postgres/pg.log.reduced file.
As a second example,
dd -if /nz/kit/log/postgres/pg.log -of /nz/kit/log/postgres/pg.log.reduced -bs 100 -skip 5
will read the /nz/kit/log/postgres/pg.log file and will skip the first 500 bytes of the /nz/kit/log/postgres/pg.log file and redirect the remainder of the file to the /nz/kit/log/postgres/pg.log.reduced file.
Historical Number
NZ222096
Was this topic helpful?
Document Information
Modified date:
17 October 2019
UID
swg21573224