如何使用文本文件中的给定参数为文本文件中的每一行重复命令 (Bash?)

How to repeat a command for every line in a textfile with given arguments from the textfile (Bash?)

我有一个结构如下的 .txt 文件:

02.01.2021-EwkqKbhcH5Q.webm.srt-00:00:26,190 --> 00:00:26,670
02.01.2021-EwkqKbhcH5Q.webm.srt-00:00:59,490 --> 00:00:59,880
02.01.2021-EwkqKbhcH5Q.webm.srt-00:03:15,570 --> 00:03:16,230
02.01.2021-EwkqKbhcH5Q.webm.srt-00:03:44,160 --> 00:03:44,730
02.01.2021-EwkqKbhcH5Q.webm.srt-00:04:32,040 --> 00:04:32,370
02.01.2021-EwkqKbhcH5Q.webm.srt-00:04:49,860 --> 00:04:50,250
02.01.2021-EwkqKbhcH5Q.webm.srt-00:05:58,200 --> 00:05:58,620
02.01.2021-EwkqKbhcH5Q.webm.srt-00:08:59,280 --> 00:08:59,760
02.01.2021-EwkqKbhcH5Q.webm.srt-00:10:20,830 --> 00:10:21,340
02.02.2021-9RaIIX8ycHg.webm.srt-00:00:23,820 --> 00:00:24,210
02.02.2021-9RaIIX8ycHg.webm.srt-00:00:40,140 --> 00:00:40,590
02.02.2021-9RaIIX8ycHg.webm.srt-00:13:03,905 --> 00:13:04,295
02.03.2021-FcNGyLY4nuw.webm.srt-00:00:25,680 --> 00:00:26,190
02.03.2021-FcNGyLY4nuw.webm.srt-00:00:44,220 --> 00:00:44,700

我想为每一行重复这个命令:

sh download_youtube.sh <youtube's URL> <HH:mm:ss.milisecs from time> <HH:mm:ss.milisecs to time> <output_file_name>

如何将 .txt 行的 url 部分和时间戳部分映射到命令?

我正在尝试制作一个工具 https://github.com/moeC137/video-recutter/blob/main/readme.md 来下载 youtube 频道上使用的单词 beeing 的所有特定实例并将所有实例编译成一个汇编。

假设输入文件的格式为固定宽度的文本,请您尝试:

#!/bin/bash

infile=                                       # input filename
count=1                                         # filename serial number
while IFS= read -r line; do                     # read the input file assigning line
    vid=${line:11:11}                           # video id of youtube
    start=${line:32:12}                         # start time
    stop=${line:49:12}                          # stop time
    file=$(printf "clip%03d.mp4" "$count")      # output filename
    (( count++ ))                               # increment the number
    echo sh download_youtube.sh "youtube.com/watch?v=$vid" "$start" "$stop" "$file"
done < "$infile"

将上面的代码保存为文件,比如mycmd.sh,然后用bash mycmd.sh file.txt作为干运行执行它。请注意 file.txt 是包含发布的下载信息的文件。如果打印输出看起来不错,删除 mycmd.shecho 并执行实际的 运行.