如何修改此sed awk命令,以使输出进入所选文件? [英] How to modify this sed awk command so that the output goes to a file of choice?
问题描述
我正在使用此SO答案中的最后一条命令 https://stackoverflow.com/a/54818581/80353
I am using the last command from this SO answer https://stackoverflow.com/a/54818581/80353
cap()(cd /tmp;rm -f *.vtt;youtube-dl --skip-download --write-auto-sub "$1";sed '1,/^$/d' *.vtt|sed 's/<[^>]*>//g'|awk -F. 'NR%8==1{printf"%s ",$1}NR%8==3'|tee cap)
此命令当前执行的操作
- 此命令会将youtube视频的字幕下载为.vtt文件,并且
- 然后在终端上打印.vtt文件的简化版本
此命令按说明工作.
在终端中,我将一次运行以上命令,然后运行cap $youtube_url
In the terminal I will run the above command once and then run cap $youtube_url
我想修改原始的cap()
函数,以使原始行为保留一个额外的部分
I would like to modify the original cap()
function so that the original behavior remains with one extra part
- 此命令会将youtube视频的字幕下载为.vtt文件(未更改)
- 然后将.vtt文件的简化版本打印到另一个文件中,该文件称为参数$ 2(已更改)
我希望如何调用新命令
最初,我将原始命令称为
How I expect to call the new command
Originally, I would call the original command as
cap $youtube_url
现在我喜欢这样做
cap $youtube_url $relative_or_absolute_path_of_text_or_markdown_file
如何修改原始的cap命令以实现所需的结果?
How do I modify the original cap command to achieve the outcome I want?
推荐答案
考虑到您希望在屏幕上看到输出以及也希望将输出保存到输出文件中,如果是这种情况,请尝试以下操作
Considering that you want to see output on screen as well as you want to save output into a output file too, if this is the case could you please try following.
cap()(cd /tmp;rm -f *.vtt;youtube-dl --skip-download --write-auto-sub "$1";sed '1,/^$/d' *.vtt|sed 's/<[^>]*>//g'|awk -F. 'NR%8==1{printf"%s ",$1}NR%8==3'|tee -a "$2")
以一种非衬里形式使用OR:
OR in non-one liner form use:
cap()(cd /tmp;rm -f *.vtt;youtube-dl --skip-download --write-auto-sub "$1";\
sed '1,/^$/d' *.vtt|sed 's/<[^>]*>//g'|awk -F. 'NR%8==1{printf"%s ",$1}NR%8==3'\
|tee -a "$2")
请确保已在变量中提供了完整路径,例如-> relative_or_absolute_path_of_text_or_markdown_file="/full/path/output_file.txt"
等,仅作为示例.我无法测试它,因为我的盒子中没有用于vtt文件等的机制.
Please make sure that you have provided complete path in your variable eg--> relative_or_absolute_path_of_text_or_markdown_file="/full/path/output_file.txt"
etc just an example. I couldn't test it since I don't have mechanism for vtt files etc in my box.
如果您不想在屏幕上打印信息,而只是想将输出保存到输出文件中,则如上所示,由于@oguz ismail的注释仅使用tee "$2"
而不是tee -a "$2"
.
In case you don't want to print information on screen and simply want to save output into output file then as @oguz ismail's comment use only tee "$2"
not tee -a "$2"
as I shown above.
这篇关于如何修改此sed awk命令,以使输出进入所选文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!