3 ms·
your database is a human-readable text file that you can grep/awk/sed freely, and a line-oriented structure makes it perfect for version control systems. But
by herdrick 7y ago
your database is a human-readable text file that you can grep/awk/sed freely, and a line-oriented structure makes it perfect for version control systems.
But in fact it's not great for grep/awk/sed/, etc. For those tools to work well, you'll find you need to keep each record on its own line.
- dredmorbius 7y agoNot for awk: BEGIN { RS="" FS="\n" } { for( i=1; i<=NF; i++ ) { nfields = split($i, afields, ": ") if( nfields != 2 ) {printf( "Bad fields count: %s %s %s\n", NR, i, $i) | "/dev/stderr"; exit 1 )} field(afield[1]) = afield[2] } } (Untested, but should be generally accurate.) That parses records based on blank lines, into fields based on lines, splitting the fields into individual data recoreds based on ": " as a regex. For more, see the GNU Awk User's Guide: https://www.gnu.org/software/gawk/manual/html_node/Multiple-Line.html#Multiple-Line https://www.gnu.org/software/gawk/manual/html_node/Multiple-...