Tool to uncat file

William Gordon Rutherdale will.rutherdale at utoronto.ca
Sun Feb 1 05:11:27 PST 2009


$ man split

This (split) is the standard unix utility to break a file up into 
pieces.  It breaks it down either by a fixed number of lines or by a 
fixed number of bytes.  Also the rules for dividing lines is 
simplistic:  simple newline division, no special escape handling.

If that doesn't suit your purpose, then you have to write your own 
custom split-like utility.  I've done that in the past.  For instance I 
once wrote a routine in Perl at work to divide Informix format .unl 
files (database dump), with special escape rules for newlines and 
special handling of binary data.

For what you're describing you probably want to write a C program to do 
the job.

-Will

Polytropon wrote:
> Dear list,
>
> before starting to code on my own, I'd like to ask if there's already a
> tool to uncat files, defining the file separation position as a string
> of bytes, usually given in hexadecimal form.
>
> An example could be this:
>
> 	% uncat -p 0x12,0x52,0xf1,0x09 file_orig
>
> It creates file_1 file_2 file_3. And, of course,
>
> 	% cat file_1 file_2 file_3 > file_orig
>
> would re-create the original file. The bytes 0x12,0x52,0xf1,0x09 tell the
> file starting pattern (-p), where a new file begins.
>
> I cannot use dd due to the fact that the files concatenated are of a
> different size. So the idea would be to look for specific byte pattern
> and then start a new file each time it occurs on input.
>
> Is there such a tool, or any other ideas


More information about the freebsd-questions mailing list