WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: programming meta awk aka awk-seption  (Read 709 times)

Online mocore

  • Hero Member
  • *****
  • Posts: 666
  • ~.~
programming meta awk aka awk-seption
« on: March 01, 2024, 10:45:30 PM »

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

run script in awk
Code: [Select]
busybox awk "$(awk '{if( NR != 1 ) print $0}' ./kv.awk)"
...
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: [Select]
diff -ud ./kv.awk-orig ./kv.awk >kv-patchkv-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

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

any one resorted similar methods ?
or have i over done the eucalyptus!??

*sings* La mer