【发布时间】:2020-08-09 12:38:52
【问题描述】:
我正在尝试使用一行代码来查找并用一长串前缀和后缀代码替换文本。
原始文件:
1. 'text that will go here'
2. 'more text that will be here'
3. 'even more text'
替换后:
youtube-dl -f 'bestvideo[height<=360]+bestaudio/best[height<=360]' --postprocessor-args "-ss 0:0:55 -to 0:1:05" "ytsearch1:text that will go here" -o "text that will go here";
youtube-dl -f 'bestvideo[height<=360]+bestaudio/best[height<=360]' --postprocessor-args "-ss 0:0:55 -to 0:1:05" "ytsearch1:more text that will be here" -o "more text that will be here";
youtube-dl -f 'bestvideo[height<=360]+bestaudio/best[height<=360]' --postprocessor-args "-ss 0:0:55 -to 0:1:05" "ytsearch1:even more text" -o "even more text";
我有以下匹配 # 的正则表达式。 ' 并替换它,但是当我尝试用代码替换它时,sed 不会接受它并发出错误。这是我试图使用的:
sed -e "s/^.*\d. '/youtube-dl -f 'bestvideo[height<=360]+bestaudio/best[height<=360]' --postprocessor-args "-ss 0:0:55 -to 0:1:05" "ytsearch1:/g" original.txt > new.txt
我知道为什么它不起作用,因为替换为其中有一堆斜杠和引号,但我不知道如何让 sed 接受这些字符来替换,所以它不会破坏整个命令。
【问题讨论】:
标签: sed