diff options
author | Jan Huwald <jh@sotun.de> | 2012-04-23 16:07:06 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2012-04-23 16:07:06 (GMT) |
commit | b9dd73d067164db087822a39960573345c06aa9b (patch) | |
tree | 6336355266aa84ca8957af588709a3e5dfa6c43b | |
parent | 7e928ded89a275f282d2e25040c33319045ee5c9 (diff) |
p2ptbl: add filter
Usage:
p2ptbl filter table program [args]
will call program with the arguments args and the result of p2ptbl
show table on standart input. stdout of program will be used as new
table. The filter program may remove lines or edit anything but the
key (first row).
-rwxr-xr-x | files/common/sbin/p2ptbl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/files/common/sbin/p2ptbl b/files/common/sbin/p2ptbl index 2048e37..0a5bae3 100755 --- a/files/common/sbin/p2ptbl +++ b/files/common/sbin/p2ptbl @@ -17,6 +17,21 @@ show () { cut -f1,3- "$1" } +filter () { + tbl="$1" + shift 1 + cut -f1,2 "$tbl" \ + | while read key version; do + echo -e "$key\t$(($version+$RANDOM))" + done > "$tbl".ver + cut -f1,3- "$tbl" \ + | "$@" \ + | join -t$'\t' "$tbl".ver - \ + > "$tbl"~ + mv "$tbl"~ "$tbl" + rm "$tbl".ver +} + update () { [ -n "$2" -a -n "$3" ] || printArgs oldversion=$(grep "^$2"$'\t' "$1" | cut -f2) @@ -86,6 +101,7 @@ $0 init table $0 get table key $0 show table $0 update table key value [interface] +$0 filter table program [args] $0 merge table foreign-table $0 gossip table target-size interface" exit 1 @@ -117,6 +133,12 @@ case "$1" in lockTable -s "$2" show "$2" ;; + filter) + tbl="$2" + shift 2 + lockTable -x "$tbl" + filter "$tbl" "$@" + ;; update) lockTable -s "$2" update "$2" "$3" "$4" "$5" |