BurntSushi / xsv

A fast CSV command line toolkit written in Rust.
The Unlicense
10.31k stars 317 forks source link

search with exit status and quiet mode #235

Open wookietreiber opened 4 years ago

wookietreiber commented 4 years ago

I'm looking for a little more [rip]grep in xsv, i.e. adding both an exit status of 1 if nothing is found and an associated quiet mode -q in either xsv search or maybe even a new subcommand. Do you think that these would be worthwhile contributions? I'd be willing to put in the effort and provide a PR.

Background / Use Case

We have third-party tools that can output XSV. We have Icinga checks that look for $stuff in that output. Using awk and friends works but is quite cumbersome, xsv would be the perfect fit for this:

function node_is_bar {
  blah | xsv xxx -d: node="^$node$" colY=bar
}

if node_is_bar
then
  echo "OK $node is bar"
  exit $nagios_status_ok
else
  echo "CRITICAL $node is not bar"
  exit $nagios_status_critical
fi

Currently, we're doing it the cumbersome way, for anyone interested in bash and awk madness, see here. We do this a lot, so I can definitely see a use case for this in xsv ;-)