dotfiles/script/dellines

26 lines
483 B
Plaintext
Raw Normal View History

2021-04-28 10:32:11 +00:00
#!/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 <pattern> <path>"
exit 1
fi
if [ -z "$filepattern" ]; then
filepattern="*"
fi
2023-10-07 08:43:32 +00:00
if [ "$(uname -s)" = "Linux" ]; then
2021-04-28 10:32:11 +00:00
echo "TODO: fix for Linux"
fi
find "$path" -type f -name "$filepattern" -print0 | LC_CTYPE=C LANG=C xargs -0 sed -i '' "/$matchpattern/d"