I imagine this is a pretty common thing to do.
Which posix utility for reads, which for writes? What are the most common file formats to do this with?
Is inplace modification possible?
My first thought was to use json and jq, but I'm interested in embracing the unix philosophy
Edit:
I don't think there is a standard tool for that. Except for
grep/awk/sed
etc. But using this you will need to care about lot of other issues like locking, format, special characters, etc. https://unix.stackexchange.com/a/21950/551103
What if didn't care about "locking, format, special characters" at all? Can someone give a minimalist implementation with grep/awk/sed
grep
/awk
/sed
are line-based text utilities. Does that mean that your keys and values are meant to be sequences of 0 or more characters other than NUL and newline encoded in the locale's charset and whose length in bytes is < 1023? – Stéphane Chazelas Nov 09 '23 at 08:33jq
would be "embracing the Unix philosophy" as much as using any other tool. You can make it easy for yourself by using an existing tool specialised in reading and writing the data you are interested in, in the format that allows your data to be expressed most conveniently. You have not mentioned if you deal with simple strings, key+value pairs, or data with a more complicated structure, e.g. arrays, many-to-many mappings, etc. Rewriting tools for the sake of rewriting them in a specific language strikes me as masochistic. – Kusalananda Nov 09 '23 at 08:40perl
or the interpreter of any other proper interpreted programming language in shells, and most of those programming languages can take the code to interpret on the command line or from a file descriptor.perl
is ubiquitous (a lot more common than systems with the full POSIX toolchest let alone with fully compliant tools) and has support for (de)serialising its data structures or tying them with on-disk DB files. – Stéphane Chazelas Nov 09 '23 at 08:46var='value...'
. – Stéphane Chazelas Nov 09 '23 at 08:50key=value
lines is that it is more human readable. But I agree the filesystem is a good way to implement this. also see https://unix.stackexchange.com/a/21979/551103 – Tom Huntington Nov 09 '23 at 23:54