首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我怎样才能修复下载脚本的博士?

我怎样才能修复下载脚本的博士?
EN

Stack Overflow用户
提问于 2012-09-03 22:00:13
回答 1查看 151关注 0票数 0

下面是这个脚本的背景:

一两年前,我试图通过混合Bash脚本和get-iplayer程序来自动下载Dr Who。这既是脚本编写的练习,也是想要观察Dr Who的练习。我从来没有让iPlayer工作,而且我太健忘了,以至于每次都不能运行get-iplayer

以下是代码:

代码语言:javascript
复制
#!/bin/bash
#Export programme names; make sure PROG is a search term that only brings up the shows you want
export PROG="Doctor Who"
export SHORT="Dr"

#Get the info you want into some text files, named after the SHORT keyword
(ls /home/$USER/Videos/iPlayer/"$PROG" | grep Doctor) >/home/$USER/Videos/iPlayer/.Code/"$SHORT"Hist.tmp
get_iplayer --listformat="<pid>: <name> - <episode>" --search="$PROG:" >/home/$USER/Videos/iPlayer/.Code/"$SHORT"Curr.tmp 

#Tidy the first file to get rid of underscores 
#then egrep to suck out the pid...schluuurp

sed -i 's/_/ /g' ./"$SHORT"Hist.tmp
#replace the underscores in the file name with spaces
egrep  -o '[bp]{1}[0-9]{2}[0-9a-z]{4}' ./"$SHORT"Hist.tmp >./"$SHORT"Hist.txt
rm ./"$SHORT"Hist.tmp
egrep  -o '[bp]{1}[0-9]{2}[0-9a-z]{4}' ./"$SHORT"Curr.tmp >./"$SHORT"Curr.txt
rm ./"$SHORT"Curr.tmp
#'b[0-9a-z]{7}' is the regex for the pid 
#--I've edited this as the pid regex no longer matches the above

sort ./"$SHORT"Curr.txt -o ./"$SHORT"Curr.txt
sort ./"$SHORT"Hist.txt -o ./"$SHORT"Hist.txt
#get things in order

diff ./"$SHORT"Curr.txt ./"$SHORT"Hist.txt > ./"$SHORT"Diff.txt
rm ./"$SHORT"Curr.txt ./"$SHORT"Hist.txt
sed -i 's/[^ ]* //1' ./"$SHORT"Diff.txt 
sed -i '1d' ./"$SHORT"Diff.txt
sed -i 's/---/\n/g'./"$SHORT"Diff.txt #<---this doesn't work?
sed '/^$/q' 

#get-iplayer --listformat="<index>" --field=pid $(cat "$SHORT"Diff.txt |  tr '\n' ' ') >./"$SHORT"Diff.txt
#sed -i '1,6d' ./"$SHORT"Diff.txt

#sed -i '/^$/,$ d' ./"$SHORT"Diff.txt

#get-iplayer --get $(cat "$SHORT"Diff.txt |  tr '\n' ' ') --output="/home/$LOGNAME/Videos/iPlayer/$PROG" --force

如果这样可行的话,我就不会在这里发帖了。有几个问题:

  • 我指出的sed -i 's/---/\n/g'./"$SHORT"Diff.txt行给出了这个错误 sed: -e expression #1, char 11: unknown option to s‘’
  • diff程序似乎没有挑选出当前的pid,我不知道它以前起作用后发生了什么变化。

有人能帮我修复这个剧本吗?

编辑

根据请求,uname; sed --version生成Linux GNU sed version 4.2.1

并将set -x放入:

代码语言:javascript
复制
+ export 'PROG=Doctor Who'
+ PROG='Doctor Who'
+ export SHORT=Dr
+ SHORT=Dr
+ ls '/home/craig/Videos/iPlayer/Doctor Who'
+ grep Doctor
+ get_iplayer '--listformat=<pid>: <name> - <episode>' '--search=Doctor Who:'

+ sed -i 's/_/ /g' ./DrHist.tmp
+ egrep -o '[bp]{1}[0-9]{2}[0-9a-z]{4}' ./DrHist.tmp
+ rm ./DrHist.tmp
+ egrep -o '[bp]{1}[0-9]{2}[0-9a-z]{4}' ./DrCurr.tmp
+ rm ./DrCurr.tmp
+ sort ./DrCurr.txt -o ./DrCurr.txt
+ sort ./DrHist.txt -o ./DrHist.txt
+ diff ./DrCurr.txt ./DrHist.txt
+ rm ./DrCurr.txt ./DrHist.txt
+ sed -i 's/[^ ]* //1' ./DrDiff.txt
+ sed -i 1d ./DrDiff.txt
+ sed -i 's/---/\n/g./DrDiff.txt'
sed: -e expression #1, char 11: unknown option to `s'
+ sed '/^$/q'

以及产出:

代码语言:javascript
复制
p00wqr1 <--one file


b00sj9q <--the contents of the other file.
b00sj9s
b010tb7
b010y5l
b0110g4
b011884
b011fnd
b011lqw

diff的输入是输出的第一行,开始为b0...的行。为什么它以前不起作用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-04 21:32:33

回答我自己的问题:

你的差异化是错误的。所以没有找到正确的PID集。以下是工作代码:

代码语言:javascript
复制
#!/bin/bash
#Export programme names; make sure PROG is a search term that only brings up the shows you want
#set -x

export PROG="Doctor Who"
export SHORT="Dr"

#Get the info you want into some text files, named after the SHORT keyword
(ls /home/$USER/Videos/iPlayer/"$PROG" | grep "$PROG") >/home/$USER/Videos/iPlayer/.Code/"$SHORT"Hist.tmp
get_iplayer --listformat="<pid>: <name> - <episode>" --search="$PROG:" >/home/$USER/Videos/iPlayer/.Code/"$SHORT"Curr.tmp 

#Tidy the first file to get rid of underscores 
#then egrep to suck out the pid...schluuurp

sed -i 's/_/ /g' ./"$SHORT"Hist.tmp
#replace the underscores in the file name with spaces
egrep  -o '[bp]{1}[0-9]{2}[0-9a-z]{4}' ./"$SHORT"Hist.tmp >./"$SHORT"Hist.txt
rm ./"$SHORT"Hist.tmp
egrep  -o '[bp]{1}[0-9]{2}[0-9a-z]{4}' ./"$SHORT"Curr.tmp >./"$SHORT"Curr.txt
rm ./"$SHORT"Curr.tmp
#'b[0-9a-z]{7}' is the regex for the pid 
#--I've edited this as the pid regex no longer matches the above

sort ./"$SHORT"Curr.txt -o ./"$SHORT"Curr.txt
sort ./"$SHORT"Hist.txt -o ./"$SHORT"Hist.txt
#get things in order

diff ./"$SHORT"Hist.txt ./"$SHORT"Curr.txt > ./"$SHORT"Diff.txt
rm ./"$SHORT"Curr.txt ./"$SHORT"Hist.txt
sed -i 's/[^ ]* //1' ./"$SHORT"Diff.txt 
sed -i '1d' ./"$SHORT"Diff.txt
sed -i 's/---/\n/g' ./"$SHORT"Diff.txt
sed '/^$/q' #<---magic?

#get the <index> from the PID
get-iplayer --listformat="<index>" --field=pid $(cat "$SHORT"Diff.txt |  tr '\n' ' ') >./"$SHORT"Diff.txt
#Sed is a magical beast
sed -i '1,6d' ./"$SHORT"Diff.txt
sed -i '/^$/,$ d' ./"$SHORT"Diff.txt
#Run get-iplayer over for each of the PIDs found, putting them in a video folder
get-iplayer --get $(cat "$SHORT"Diff.txt |  tr '\n' ' ') --output="/home/$LOGNAME/Videos/iPlayer/$PROG" --force
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12254476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档