Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:25:40+00:00 2026-06-10T22:25:40+00:00

Here is the background to this script: A year or two ago I tried

  • 0

Here is the background to this script:

A year or two ago I tried to automate downloading Dr Who by mixing Bash Scripting and the get-iplayer program. This was both an exercise in scripting and wanting to watch Dr Who. I’ve never gotten iPlayer to work, and I’m too forgetful to run get-iplayer each time.

Here is the code:

#!/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

Now I wouldn’t be posting here if this worked. There are a few issues:

  • The sed line I pointed out sed -i 's/---/\n/g'./"$SHORT"Diff.txt give me this error
    sed: -e expression #1, char 11: unknown option to s’`
  • The diff program doesn’t seem to pick out the current pid I don’t know what changed since it worked before.

Is anyone able to help me fix this script?

edit

As requested
uname; sed --version
produces
Linux
GNU sed version 4.2.1

And putting set -x in:

+ 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'

And the output:

p00wqr1 <--one file


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

The input of the diff is the first line of output and the lines beginning b0.... Why isn’t it working when it did before?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:25:42+00:00Added an answer on June 10, 2026 at 10:25 pm

    Answering my own question:

    Your diff was the wrong way round. So it wasn’t finding the right set of PIDs. Here is the working code:

    #!/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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am including jQuery in background_page like this, <script type=text/javascript src=libs/jquery.js></script> Here's the problem:
Background: Firstly, I'm unsure if this is even called a metabox Here's an example
I have this query which works correctly in MySQL. More background on it here
Ok, I need help. This is my first question here. Background: I am working
I have tried to get several examples that I have found on here and
I have this script that positions a div's background in proportion with the window
I have this small script: http://jsfiddle.net/gmAjC/ <input name=n1 value=test> <br/><span></span> <br/> <span style=background-color:red>after input</span>
The two paragraphs after this are background information in case I'm thinking of this
I have googled an serached a lot here about background runnin aps but have
Here is the background, I am trying to create a DSL to allow customer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.