Add support for multiple files at the sime time
This commit is contained in:
parent
0086fa7fb9
commit
7feb65e8f9
|
@ -1,5 +1,5 @@
|
|||
# fsub
|
||||
`fsub` is a very simple script (less than 50 lines of code) for cleaning a .srt file
|
||||
`fsub` is a very simple script (less than 60 lines of code) for cleaning a .srt file
|
||||
|
||||
# Usage
|
||||
`fsub <file>`
|
||||
|
|
30
fsub
30
fsub
|
@ -4,26 +4,37 @@ 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
|
||||
|
||||
for arg in "$@"; do
|
||||
if [ ! -f "$arg" ]; then
|
||||
echo "$arg is not a file"
|
||||
usage
|
||||
fi
|
||||
if [ "${arg: -4}" != ".srt" ]; then
|
||||
echo "$arg is not a .srt file"
|
||||
usage
|
||||
fi
|
||||
done
|
||||
|
||||
[ -f "$FSUBRC" ] || touch $FSUBRC
|
||||
|
||||
awk '
|
||||
BEGIN {
|
||||
for arg in "$@"; do
|
||||
awk '
|
||||
BEGIN {
|
||||
n = 1
|
||||
i = 0
|
||||
while(getline < "'$FSUBRC'") {
|
||||
blacklist[i] = $0
|
||||
i++
|
||||
}
|
||||
}
|
||||
/^[[:digit:]]+[[:space:]]*$/ {
|
||||
}
|
||||
/^[[:digit:]]+[[:space:]]*$/ {
|
||||
getline
|
||||
time = $0
|
||||
|
||||
|
@ -43,5 +54,6 @@ BEGIN {
|
|||
print time
|
||||
for(j = 0; j < linen; j++)
|
||||
print lines[j]
|
||||
}' "$1" | sed 's/\r//' > /tmp/fsub
|
||||
mv /tmp/fsub "$1"
|
||||
}' "$arg" | sed 's/\r//' > /tmp/fsub
|
||||
mv /tmp/fsub "$arg"
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue