Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 17th, 2005, 5:44 PM   #1
Jimineep
Newbie
 
Join Date: May 2005
Posts: 2
Rep Power: 0 Jimineep is on a distinguished road
script to obtain jpgs and compress them and save them to an output file

I'm trying to create a fairly simple bash script which will search a given site for all of the jpg images on the site...its not working though...any ideas?? Am I even using the right commands for this job!!!!? Or is it the piping?

# a friendly greeting

echo hello $USER, hope all is well

echo What is the website you wish to download your images from? Remember to give the full url including http://

read SITE

echo And what compression ratio would you like? from 0-100 I would recommend a value of 65 to get a balance of file size and quality

echo A lower number gives less quality but a smaller file size, A higher number gives greater quality but makes a bigger file.

# get the jpegs from the site

wget -O - $SITE

#filter out all of the jpeg files

grep -O - -f "\.jpg$" |

#compress the jpeg file to make it smaller (although lower quality) and put it in a directory

| cjpeg - -quality $COMPR > ~/compressed/

[/code]

cheers x
Jimineep is offline   Reply With Quote
Old May 18th, 2005, 8:00 AM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
One problem is that wget -O - $SITE doesn't do what you're expecting it to. It would download the index page of the site and write the code to stdout.

Secondly, your pipelines are wrong. Some examples of how you can use pipelines:

1. cat /etc/passwd | grep mackenga | gzip -9 > foo
2. ps -al | grep netscape
3. cat words | sort | uniq > /usr/dict/words

1 uses cat to type out the password file, grep to find the line with my details, gzip to compress these (pointlessly; I was groping for a decent example!) and writes them to a file called foo in the current directory.

2 gets a list of all my running processes and displays on the terminal only those lines that match "netscape".

3 reads a file called words in the current directory and pipes them to sort (which orders them ascibetically I think by default) then to uniq (which removes duplicate lines, but assumes ordered input) and writes the result to /usr/dict/words.

Downloading all the JPG files from a site is also not really that simple a job I'm afraid. Even if you just want the images from the main page, you need to do some complicated things to parse out the URLs then fetch each of those (though I do think wget may be able to do that for you; investigate the -r option. I don't have the manpage in front of me but I have a good feeling about that).

Just to add: ah yes, http://www.lns.cornell.edu/public/CO...et_3.html#SEC7 should be useful for doing recursive retrievals using wget.

Last edited by mackenga; May 18th, 2005 at 8:04 AM.
mackenga is offline   Reply With Quote
Old May 18th, 2005, 9:16 AM   #3
Jimineep
Newbie
 
Join Date: May 2005
Posts: 2
Rep Power: 0 Jimineep is on a distinguished road
OK, scrap that, it is too complex for my first ever script!!

So i'm gonna try a simpler one... ure use of uniq inspired me

So could I use wgrep to search a specific website, and then use sort to take all of the words from this website, then arrange them in order and uniq write them to a specific dictionary:

something like this

echo what dictionary do you want to add to?

read LANG

and what webpage do you want to look up in order to find words?

read URL

lynx -dump $URL | cat | sort | uniq >> /usr/dict/$LANG

I am a little unsure of the piping...do I not need to define STDOUT/STDIN?

I wont get to test anythign until tomorrow so if anyone is running linux I would be grateful if u could help me out and tell me if it works or if there are any glaring errors

I've gotta get my head round all this by september when I begin my masters in bioinformatics! I am supposed to be competent with the CLI :eek:
Jimineep is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC