Off-Topic > Off-Topic - Tiny Core Lounge
programming meta awk aka awk-seption
(1/1)
mocore:
while pondering how it might be possible to (re)write kv.awk
while preserving line ordering and processing the file in more traditional `awk like filtering style
i ended up using the below method(s) to allow prototyping/editing the script from the command line
print script without shebang
--- Quote ---awk '{if( NR != 1 ) print $0}' ./kv.awk
--- End quote ---
run script in awk
--- Code: ---busybox awk "$(awk '{if( NR != 1 ) print $0}' ./kv.awk)"
--- End code ---
...
https://github.com/Gumnos/kv.awk # A dumb key/value store implemented in awk & plain-text files
as previously mentioned @ https://forum.tinycorelinux.net/index.php/topic,25301.msg171402.html#msg171402
https://raw.githubusercontent.com/Gumnos/kv.awk/master/kv.awk
some small changes after some testing
--- Code: ---diff -ud ./kv.awk-orig ./kv.awk >kv-patch
--- End code ---
kv-patch attached .. as the forum server didnt like code section
more EG
---
quit printing script when BEGIN is found , and append some extra to the end of the script ;D
echo some input
run script
setting KEY abc to VALUE xyz
--- Quote ---echo un du trois | DEBUG=y busybox awk "$(awk '{if( $0 ~ "^BEGIN" ) exit; if( NR != 1 ) print $0}' ./kv.awk)"'BEGIN{ main() }; {print $0}' test.txt set abc xyz
--- End quote ---
get value of key abc
also pass unknown key !
--- Quote ---echo abcd | DEBUG=y busybox awk "$(awk '{if( $0 ~ "^BEGIN" ) exit; if( NR != 1 ) print $0}' ./kv.awk)"'BEGIN{ main() }; {print $0}' test.txt get abc cde
--- End quote ---
any one resorted similar methods ?
or have i over done the eucalyptus!??
*sings* La mer
Navigation
[0] Message Index
Go to full version