From 41b4b466052f65ea29e9a7b97c19a921b395d536 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 1 Aug 2018 19:05:13 +0300 Subject: add str_grep, str_grep_word --- %HOME%/.bash_utils/text.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to '%HOME%') diff --git a/%HOME%/.bash_utils/text.sh b/%HOME%/.bash_utils/text.sh index e72167f..da21b5c 100644 --- a/%HOME%/.bash_utils/text.sh +++ b/%HOME%/.bash_utils/text.sh @@ -265,3 +265,29 @@ str_join() ( done echo ) + +str_grep() ( + set -o errexit -o nounset -o pipefail + + if [ "$#" -ne 1 ]; then + echo "usage: ${FUNCNAME[0]} PATTERN" >&2 + return 1 + fi + + local pattern="$1" + + find . -type f -exec grep --fixed-strings --binary-files=without-match --regexp="$pattern" -- {} + +) + +str_grep_word() ( + set -o errexit -o nounset -o pipefail + + if [ "$#" -ne 1 ]; then + echo "usage: ${FUNCNAME[0]} PATTERN" >&2 + return 1 + fi + + local pattern="$1" + + find . -type f -exec grep --basic-regexp --binary-files=without-match --regexp="\b$pattern\b" -- {} + +) -- cgit v1.2.3