Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

sed cannot delete forward slash in while loop?

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
shams
Posts: 144
Joined: 2006-02-17 15:37

sed cannot delete forward slash in while loop?

#1 Post by shams »

I am downloading online videos with a bash script this is the code of script test.sh:

Code: Select all

#!/bin/bash
while read line
 do
"/usr/bin/wget" $line
sed -i "/$line/d" urls
done  <urls
The while loop read the videos url from the urls file and parse them to the wget for dwonlaod, i write the wget for easy of exmple in this code otherwise i use another script to downlaod the embed videos , the code

Code: Select all

sed -i "/$line/d" urls 
delete the url of videos from the urls file when it is download is complete.
The problem is http address contain the foreward slashes "/" and sed cannot delete them and get error, this is the urls file:

Code: Select all

http://download.wavetlan.com/SVV/Media/HTTP/MP4/ConvertedFiles/Media-Convert/Unsupported/test7.mp4
http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test3_Talkingheadclipped_mp4_480x360.mp4
http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test4_Talkingheadclipped_mp4_480x320.mp4
http://download.wavetlan.com/SVV/Media/HTTP/H264/Other_Media/H264_test8_voiceclip_mp4_480x320.mp4
This is output of the test.sh:

Code: Select all

# ./test.sh
http://download.wavetlan.com/SVV/Media/HTTP/MP4/ConvertedFiles/Media-Convert/Unsupported/test7.mp4
sed: -e expression #1, char 8: unknown command: `/'
http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test3_Talkingheadclipped_mp4_480x360.mp4
sed: -e expression #1, char 8: unknown command: `/'
http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test4_Talkingheadclipped_mp4_480x320.mp4
sed: -e expression #1, char 8: unknown command: `/'
http://download.wavetlan.com/SVV/Media/HTTP/H264/Other_Media/H264_test8_voiceclip_mp4_480x320.mp4
sed: -e expression #1, char 8: unknown command: `/'

User avatar
saulgoode
Posts: 1445
Joined: 2007-10-22 11:34
Been thanked: 4 times

Re: sed cannot delete forward slash in while loop?

#2 Post by saulgoode »

Try quoting the lines:

Code: Select all

sed -i "/\"$line\"/d" urls
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan

shams
Posts: 144
Joined: 2006-02-17 15:37

Re: sed cannot delete forward slash in while loop?

#3 Post by shams »

This is the modefy code from the previous post:

Code: Select all

#!/bin/bash
while read line
do
echo $line
sed -i "/\"$line\"/d" urls
done < urls

and this is the output of above code:

Code: Select all

# ./test.sh
http://download.wavetlan.com/SVV/Media/HTTP/MP4/ConvertedFiles/Media-Convert/Unsupported/test7.mp4
sed: -e expression #1, char 9: unknown command: `/'
http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test3_Talkingheadclipped_mp4_480x360.mp4
sed: -e expression #1, char 9: unknown command: `/'
http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test4_Talkingheadclipped_mp4_480x320.mp4
sed: -e expression #1, char 9: unknown command: `/'
http://download.wavetlan.com/SVV/Media/HTTP/H264/Other_Media/H264_test8_voiceclip_mp4_480x320.mp4
sed: -e expression #1, char 9: unknown command: `/

User avatar
dilberts_left_nut
Administrator
Administrator
Posts: 5347
Joined: 2009-10-05 07:54
Location: enzed
Has thanked: 13 times
Been thanked: 66 times

Re: sed cannot delete forward slash in while loop?

#4 Post by dilberts_left_nut »

sed can use arbitrary delimeters.

Code: Select all

sed -i '#$line#d' urls
maybe this?
AdrianTM wrote:There's no hacker in my grandma...

Post Reply