Skip to content
Advertisement

How do I extract everything in a file after the first null character from shell

I have a file that looks like this: some ascii stuffsome more ascii stuffand a little more ascii stuff.

I want to extract everything after the first . So my output after this process would be some more ascii stuffand a little more ascii stuff

How would I go about doing this? This is done within initramfs so my access to commands is somewhat limited. I do have cut, grep, and awk which I’ve been trying to get work, but I’m just not having any luck.

This utils are mostly busybox and sh for the shell

Advertisement

Answer

Easily done, with nothing but shell builtins (well, cat isn’t a builtin, but you can substitute it with the actual intended consumer of your stream):

JavaScript

read -d '' reads everything, one byte at a time, up to the first NUL on stdin. What’s left on that stream, thus, is all the content after that NUL.


You can test it as follows:

JavaScript

…which properly emits:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement