Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-07-2010, 04:11 PM   #1
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



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

wget "$i" > $list

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

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492

have a look at the following threads first:

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.

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
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,628

Rep: Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943
Well I am a little concerned with the whole script!!
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??
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.
wget "$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
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 346

Rep: Reputation: 152Reputation: 152
I'm assuming there is directory containing files such as
from downloading
and you want to extract the jpg relative URL from the htm file, download the jpg file, and save it as
for filename in *battery.htm;do
 pp=$(grep -o '/productpic/[^"]*\.jpg' "$filename")
 wget -O "${filename%.htm}.jpg" "$pp"
Old 10-07-2010, 10:00 PM   #5
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.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:55 AM.

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