sort file specifying record length

I've been searching high and low for this...but, maybe I'm just missing something. I have a file to be sorted that, unfortunately, contains binary data at the end of the line. As you may guess, this binary data may contain a newline character, which messes up the sort. I think I could resolve this by letting 'sort' know the record length (line length) of each line, but I can't seem to find out how to do that. Is there a way to do this? If so, can someone point me the way?

Thanks in advance!!

There's nothing you can tell sort that would make the situation workable. The problem is that sort is a line-oriented tool. If there is a newline-valued byte in the binary data, sort will treat the binary data before and after that byte as individual lines.

You are going to need some way to pre-process the input before feeding it to sort, so that it can do its job properly.

If you'd like further help, we'll need to know as much as possible about the characteristics of the input data (including the always annoying-when-not-mentioned special cases).

Regards and welcome to the forum,
Alister

I think I can work it to use some perl...I was just hoping 'sort' could do it somehow. Thanks for your quick response!

Just a thought (without more info) but have you tried using strings then pipe that to sort.

Just tried it...it appears to do that same thing. Thanks for the idea, however!

GNU sort has -z option which would delimit records with nulls instead of new lines, but I guess it won't help in this case.