From b9dd73d067164db087822a39960573345c06aa9b Mon Sep 17 00:00:00 2001 From: Jan Huwald Date: Mon, 23 Apr 2012 16:07:06 +0000 Subject: 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). 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" -- cgit v0.10.1