Add helper scripts

This commit is contained in:
Augusto Gunsch
2021-11-02 16:33:23 -03:00
parent 64c13e2974
commit 9a3cff1cfa
3 changed files with 108 additions and 34 deletions

View File

@@ -4,46 +4,56 @@ set -e
FSUBRC=~/.config/fsubrc
usage() {
echo "usage: fsub <file>"
echo "usage: fsub <files>"
echo "fsub expects $FSUBRC to have a blacklist of words"
exit 1
}
[ -z $1 ] && usage
[ -f $1 ] || usage
[ -z $2 ] || usage
[ -f $FSUBRC ] || touch $FSUBRC
[ -z "$1" ] && usage
cp $1 $1.bak
awk '
BEGIN {
n = 1
i = 0
while(getline < "'$FSUBRC'") {
blacklist[i] = $0
i++
for arg in "$@"; do
case "$arg" in
*.srt )
if [ ! -f "$arg" ]; then
echo "$arg is not a file"
usage
fi ;;
*) echo "$arg is not a .srt file"; usage ;;
esac
done
[ -f "$FSUBRC" ] || touch $FSUBRC
for arg in "$@"; do
awk '
BEGIN {
n = 1
i = 0
while(getline < "'$FSUBRC'") {
blacklist[i] = $0
i++
}
}
}
/^[[:digit:]]+[[:space:]]*$/ {
getline
time = $0
/^[[:digit:]]+[[:space:]]*$/ {
getline
time = $0
linen = 0
while(getline) {
lines[linen] = $0
linen++
if($0 ~ /^[[:space:]]*$/) break
}
linen = 0
while(getline) {
lines[linen] = $0
linen++
if($0 ~ /^[[:space:]]*$/) break
}
for(j = 0; j < i; j++)
for(k = 0; k < linen; k++)
if(lines[k] ~ blacklist[j]) next
for(j = 0; j < i; j++)
for(k = 0; k < linen; k++)
if(lines[k] ~ blacklist[j]) next
print n
n++
print time
for(j = 0; j < linen; j++)
print lines[j]
}' $1 | sed 's/\r//' > /tmp/fsub
mv /tmp/fsub $1
rm $1.bak
print n
n++
print time
for(j = 0; j < linen; j++)
print lines[j]
}' "$arg" | sed 's/\r//' > /tmp/fsub
mv /tmp/fsub "$arg"
done