开发者

output only blocks of size n with offset of multiple of stride k from start of binary input in shell

given a blocksize of n and another size k, I search for a way to only output blocks with an offset from the start of an input of a multiple of k.

imagine a file consisting of a number of 4-tuples of 2-byte data. now given this input I want only the first entry of each tuple.

example input:

00 00 11 11 22 22 33 33
44 44 55 55 66 66 77 77
88 88 99 99 aa aa bb bb
cc cc dd dd ee ee ff ff

example output with n=2 and k=8:

00 00 44 44 88 88 cc cc

which is only the first "column" of the input.

Now while it would be simple to do this in perl, python, I need this functionality in a shell script as the target system does not have perl or python but only basic utilities. I'm hoping there is a way to misuse an existing tool for that. If it is not possible I would write some C doing that but I would like to avoid it.

One usecase w开发者_开发问答ould be to extract one audio channel from a raw audio file.


A term you might search for (other than "zebra stripes") is "stride." That's what some people call this idea of skipping k bytes each time.

It's not entirely clear from your post, but it looks like you actually want to be able to insert this filter in a pipeline and have it consume raw bytes and output the same. If this is the case, I'm not sure how it can be done easily in plain shell script, so would suggest you either hunker down and write it in C, or get Python or something installed on the target system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜