我有一个.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频道上使用的所有特定的单词实例,并将所有实例编译成一个编译。
发布于 2021-11-16 22:33:36
假设输入文件被格式化为固定宽度的文本,请尝试:
#!/bin/bash
infile=$1 # 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.sh的mycmd.sh并执行实际运行。
https://stackoverflow.com/questions/69982768
复制相似问题