From 5fe874d5516e20d4b83ceeacc19de685b69a69c0 Mon Sep 17 00:00:00 2001 From: jrichardsz Date: Sun, 7 Aug 2022 19:28:28 -0500 Subject: [PATCH] add search and replace --- commands/replace.sh | 15 +++++++++++++++ commands/search.sh | 9 +++++++++ 2 files changed, 24 insertions(+) create mode 100644 commands/replace.sh create mode 100644 commands/search.sh diff --git a/commands/replace.sh b/commands/replace.sh new file mode 100644 index 0000000..6246027 --- /dev/null +++ b/commands/replace.sh @@ -0,0 +1,15 @@ +file_location=$1 +string_to_search=$2 +string_to_replace=$3 + +string_to_search_scaped=$(echo $string_to_search | sed 's_/_\\/_g') +string_to_replace_scaped=$(echo $string_to_replace | sed 's_/_\\/_g') + +echo "search ocurrences of: $string_to_search_scaped" +grep -rnw $file_location -e $string_to_search_scaped | wc -l + + +sed -e "s/$string_to_search_scaped/$string_to_replace_scaped/g" $file_location + +echo "search ocurrences of: $string_to_search" +grep -rnw $file_location -e $string_to_search | wc -l diff --git a/commands/search.sh b/commands/search.sh new file mode 100644 index 0000000..c830f71 --- /dev/null +++ b/commands/search.sh @@ -0,0 +1,9 @@ +file_location=$1 +string_to_search=$2 +string_to_replace=$3 + +string_to_search_scaped=$(echo $string_to_search | sed 's_/_\\/_g') +string_to_replace_scaped=$(echo $string_to_replace | sed 's_/_\\/_g') + +echo "search ocurrences of: $string_to_search_scaped" +grep -rnw $file_location -e $string_to_search_scaped | wc -l