LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-07-2010, 04:11 PM   #1
p0rn0saurus
LQ Newbie
 
Registered: Oct 2010
Posts: 1

Rep: Reputation: 0
Help with this script


Im trying to grab the jpg and rename it accord to ls. what do i need to do to get this working? ls will list a bunch of .htm files

Quote:
#!/bin/bash

list=`ls`

for i in `cat $list | grep productpic |sed -e 's/ //g'| sed -e 's/.*productpic//' | sed -e 's/jpg.*//' | sed 's/[.]/.jpg/g'`
do

wget "http://www.digi163.com/battery/productpic$i" > $list

done
 
Old 10-07-2010, 04:38 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,620

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
Hi,

have a look at the following threads first:
http://www.linuxquestions.org/questi...-files-831347/
http://www.linuxquestions.org/questi...lename-827305/
http://www.linuxquestions.org/questi...olders-804100/
http://www.linuxquestions.org/questi...751/page2.html

Renaming files is a common task and it has been covered several times now. There is probably something in the links above that will solve your problem. Post again if you have trouble understanding a command.

[EDIT]
Just saw that you are using wget. Are you trying to keep a local directory in sync with the contents of a webpage? Please provide some sample filenames and how you want them to rename.

Last edited by crts; 10-07-2010 at 04:43 PM.
 
Old 10-07-2010, 05:02 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Well I am a little concerned with the whole script!!
Code:
list=`ls`
So where ever I run this, all files and directories will be thrown into 'list'. Is this what you really want? Seems you are only looking for jpg files??
Code:
for i in `cat $list | grep productpic |sed -e 's/ //g'| sed -e 's/.*productpic//' | sed -e 's/jpg.*//' | sed 's/[.]/.jpg/g'`
This has to be the most convoluted way I have seen to try and avoid word splitting I have seen for a while.
Code:
wget "http://www.digi163.com/battery/productpic$i" > $list
This one is possibly my favourite. See problem one above and then ask yourself what the possible value is that might be stored in '$list'??
Not only that, but you went to all the trouble of avoiding word splitting for your for loop but then didn't quote this variable so here it is again??

Let us go back to some basics:

1. What does the directory structure look like where you are running ls?

2. Provide at least one complete url (can be fake) so we understand what you are wgetting?

3. What do you wish to be the contents of the file and of what file?
 
Old 10-07-2010, 06:55 PM   #4
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 336

Rep: Reputation: 141Reputation: 141
I'm assuming there is directory containing files such as
HP-HSTNN-LB31-battery.htm
from downloading
http://www.digi163.com/battery/HP-la...31-battery.htm
and you want to extract the jpg relative URL from the htm file, download the jpg file, and save it as
HP-HSTNN-LB31-battery.jpg.
Code:
#!/bin/bash
for filename in *battery.htm;do
 pp=$(grep -o '/productpic/[^"]*\.jpg' "$filename")
 wget -O "${filename%.htm}.jpg" "http://www.digi163.com/battery$pp"
done
 
Old 10-07-2010, 10:00 PM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
@OP, how is your htm files being downloaded in the first place? With wget, you can also download those image files.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 03:41 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
set variables in a bash script; ansi PS1 color script donnied Programming 4 11-21-2007 12:33 PM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 11:48 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration