From 37dbd9d6e0fe5c3f43babc89a67beea68933e66a Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Wed, 28 Apr 2021 12:32:11 +0200 Subject: [PATCH] Add dellines script --- script/dellines | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 script/dellines diff --git a/script/dellines b/script/dellines new file mode 100755 index 0000000..a67e402 --- /dev/null +++ b/script/dellines @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# +# dellines deletes lines in multiple files matching a regex +# Example: dellines '^//' src/ *.go + +set -e + +matchpattern="$1" +path="$2" +filepattern="$3" + +if [ -z "$path" ]; then + echo "Usage: dellines " + exit 1 +fi + +if [ -z "$filepattern" ]; then + filepattern="*" +fi + +if [ $(uname -s) = "Linux" ]; then + echo "TODO: fix for Linux" +fi + +find "$path" -type f -name "$filepattern" -print0 | LC_CTYPE=C LANG=C xargs -0 sed -i '' "/$matchpattern/d"