Register
It is currently Sun Nov 23, 2014 10:56 am

scafy.com video grabber. pattern matching problem.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue Mar 17, 2009 11:26 am   

Joined: Mon Apr 09, 2007 5:05 am
Posts: 3
Code:
#!/bin/bash
#usage: ./karipap.sh video_id
#ex: ./karipap.sh 1234
id=$1
url=scafy.com/flv_player/data/playerConfig/$id.xml
wget $url -O ayam
vid=`cat ayam |grep files/ |cut -c61-114`
wget -c $vid


I want to get the exact video file url.
The codes above is working with certain video file with 4 digit id
ex: 1234

Can someone point me how to to this with awk/sed/anything? just thinking I can;t achieve this with grep and cut combination.

or maybe that just me. :oops: [/code]


Top
 Profile  
 PostPosted: Wed Mar 18, 2009 2:55 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Let me see if I understood you right.
You're downloading that xml file and then want to cut out the url to something?

Code:
#!/bin/bash
# Set the url variables :)
id=$1
url="http://scafy.com/flv_player/data/playerConfig/$id.xml"
# Download the file to $pid.url (this is just to uniqueify the filename)
wget $url -O /tmp/$$.url
# the sed line looks throu what we just grep:ed for and searches for something starting with path="
# then it buffers whatever is contained between " and " and then replaces the whole line with the buffer.
file=$(grep files /tmp/$$.url | sed "s/^.*path=\"\(.*\)\">$/\1/")
# Download the url that we got above.
wget -c $file
# Remove the temp file so we don't get alot of crap lying around.
rm /tmp/$$.url


You were right on the money, the sed line is just what you needed :)

ps. If you're using cat file | grep you can just aswell just use grep "pattern" file, this way you only need to execute 1 program instead of 2. This saves you some time when doing large scripts that process alot of data :) ds.

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Tue Mar 24, 2009 9:40 am   

Joined: Mon Apr 09, 2007 5:05 am
Posts: 3
thanks fredrik.

hehe :twisted:


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP