4 ms·
> Read from specific bytes of a file Especially handy when you've fed in a huge amount of JSON (sometimes all on one line because, y'know, why not) into jq and
by zimpenfish 4y ago
> Read from specific bytes of a file
Especially handy when you've fed in a huge amount of JSON (sometimes all on one line because, y'know, why not) into jq and you get the inscrutable output:
parse error: Invalid numeric literal at line 1, column 236162512
- dredmorbius 4y agoUgh! I'll keep that in mind, json-parsing being among my current hobbies...
- nemetroid 4y agoTail can do this, too: tail --bytes=+236162512
- zimpenfish 4y agoHandy but `dd` is much better at giving you a limited context to look at - `dd bs=1 skip=236162504 count=20' just gives you 8 before and 12 after. (edit: I do have to concede that the `tail|head` version is much faster than the `dd` - ~11s vs ~65s in my quick test with that ^skip)
- dredmorbius 4y agoI suspect you'd get better performance increasing the blocksize, and if necessary trimming the output in a second pass. Large blocks -> efficient I/O. Within reason.
- nrclark 4y agoA note here: if you're using GNU dd, you can also use iflag=count_bytes and then set the block-size to whatever you want. That'll give you the best of both worlds.
- zimpenfish 4y agoAh, good to know. With a block size of 1M, that brings the `dd` version down to ~15s.