From 251b8a763a9cd6657bc0c46514a5679756b9865b Mon Sep 17 00:00:00 2001 From: Chris Aumann Date: Wed, 8 May 2024 22:15:09 +0200 Subject: [PATCH] Use awk instead of sed when parsing du output (#112) This feel a little less "magic", is better readable and maintainable. Might have a slight impact on performance, too. --- directory-size.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/directory-size.sh b/directory-size.sh index 3e03f04..5357901 100755 --- a/directory-size.sh +++ b/directory-size.sh @@ -13,4 +13,4 @@ echo "# HELP node_directory_size_bytes Disk space used by some directories" echo "# TYPE node_directory_size_bytes gauge" du --block-size=1 --summarize "$@" \ - | sed -ne 's/\\/\\\\/;s/"/\\"/g;s/^\([0-9]\+\)\t\(.*\)$/node_directory_size_bytes{directory="\2"} \1/p' + | awk '{ print "node_directory_size_bytes{directory=\"" $2 "\"} " $1 }'