このスクリプトの背景は次のとおりです。
get-iplayer
1、2年前、私はBash Scriptingとプログラムを組み合わせて、DrWhoのダウンロードを自動化しようとしました。これは、スクリプティングの演習であり、ドクター・フーを見たいということでもありました。私はiPlayerを動作させたことがなく、get-iplayer
毎回実行するのを忘れすぎています。
コードは次のとおりです。
#!/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行は
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
て:
+ 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'
そして出力:
p00wqr1 <--one file
b00sj9q <--the contents of the other file.
b00sj9s
b010tb7
b010y5l
b0110g4
b011884
b011fnd
b011lqw
の入力は、diff
出力の最初の行とで始まる行b0...
です。以前は機能していなかったのはなぜですか?