3 ms·
head, read, and sed can be used for seeking forward according to POSIX (see the INPUT FILES section here <https://pubs.opengroup.org/onlinepubs/9799919799/utili
by oguz-ismail 2y ago
head, read, and sed can be used for seeking forward according to POSIX (see the INPUT FILES section here <https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap01.html#tag_18_04 https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V...>). I doubt non-GNU implementations support it though.
- rwmj 2y agohead was used for this purpose in the xz backdoor.
- Someone 2y agoIf it’s in POSIX, chances are the BSDs implement it, too. I think seeking a specific number of bytes and then writing data there will be a problem, though. For seeking n bytes, read nor sed will work; they work with lines. sed is the only one of those that can write, and POSIX doesn’t appear to have the -i option for in-place editing (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/s...) So, I think head for seeking followed by sed (or ed or vi, but sed is the simpler tool, I think) for replacing the first n characters, redirecting to a temp file and then doing a mv is your only option. Advantage will be that writes will be atomic; disadvantage that it will be slow
- hun3 2y agoI think dd might be more reliable. (Is dd POSIX?)
- rmwaite 2y agoYep: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/dd.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/d...