2020-11-05 17:24:31 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-08-28 14:16:37 +00:00
|
|
|
# batch replace: echo file1\nfile2 | br <REGEX> <NEWSTR>
|
2020-11-08 16:26:14 +00:00
|
|
|
# rule 1: use single quote '
|
|
|
|
# rule 2: //// for literal /
|
|
|
|
|
|
|
|
set -e
|
|
|
|
FILES=$(awk '{print}')
|
|
|
|
COL=$(tput cols)
|
|
|
|
PAT=$1
|
|
|
|
STR=$2
|
|
|
|
export COL PAT STR
|
2020-11-05 17:24:31 +00:00
|
|
|
|
2020-11-08 16:26:14 +00:00
|
|
|
echo "$FILES" | while IFS= read -r FILE; do
|
2020-11-18 12:29:04 +00:00
|
|
|
fr "$FILE"
|
2020-11-08 16:26:14 +00:00
|
|
|
done | less
|
2020-11-05 17:24:31 +00:00
|
|
|
|
2020-11-08 16:26:14 +00:00
|
|
|
printf "Are you sure [y/N]? "
|
|
|
|
read -r YN < /dev/tty
|
|
|
|
if [ "$YN" = 'y' ]; then
|
|
|
|
echo "$FILES" | while IFS= read -r FILE; do
|
|
|
|
TMP=$(mktemp)
|
2020-11-18 12:29:04 +00:00
|
|
|
REP=1 fr "$FILE" > "$TMP"
|
2020-11-08 16:26:14 +00:00
|
|
|
mv "$TMP" "$FILE"
|
|
|
|
done
|
|
|
|
fi
|