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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-05-2007, 11:54 AM
|
#1
|
LQ Newbie
Registered: Nov 2007
Location: Canton, Ohio
Distribution: Ubuntu, Mepis, Damn Small Linux,
Posts: 10
Rep:
|
question about shell script
I hope this is the right place for this post...
I have a shell script (I have forgotten the original author) that will search recursively through directories looking for duplicate files, It then generates a second script to remove the duplicates with one file per line. Each file is commented out. I would like to be able to automatically remove the comment from one of the lines. Then I can run script to delete the duplicate files, in this case they are .jpg files.
I will include part of the script as an example:
I would like to remove the comment from one file leave the other (oldest date) commented out. In the following example I would like to remove the comment from the lines that have been placed in bold. Any help would be greatly appreciated, the actual file is huge somewhere around 2072 lines.
#! /bin/sh
#rm ./2006-05-09/100_4375.jpg
#rm ./2006-06-25/100_4375.jpg
#rm ./2006-08-04/100_4906.jpg
#rm ./2006-08-26/100_4906.jpg
#rm ./2006-10-21/100_4906.jpg
#rm ./2004-11-25/100b0270.jpg
#rm ./2004-12-24/100b0270.jpg
tmbigrigg
|
|
|
11-05-2007, 12:13 PM
|
#2
|
Moderator
Registered: May 2001
Posts: 29,417
|
Wouldn't it be better to post the (D/L location of) the script? With all due respect but writing a kludge for this instead of the source seems a bit of a waste of time.
|
|
|
11-05-2007, 12:18 PM
|
#3
|
LQ Newbie
Registered: Nov 2007
Location: Canton, Ohio
Distribution: Ubuntu, Mepis, Damn Small Linux,
Posts: 10
Original Poster
Rep:
|
Here is where I found the original script: http://elonen.iki.fi/code/misc-notes...les/index.html
OUTF=rem-duplicates.sh;
echo "#! /bin/sh" > $OUTF;
find "$@" -type f -print0 |
xargs -0 -n1 md5sum |
sort --key=1,32 | uniq -w 32 -d --all-repeated=separate |
sed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\1/g;s/(.+)/#rm \1/' >> $OUTF;
chmod a+x $OUTF; ls -l $OUTF
|
|
|
11-05-2007, 12:47 PM
|
#4
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
to selectively modify certain lines in a file, you would have to be able to define some common attribute. In your example, it appears that the common attribute is that you want to modify based on folder names which are dates later than the first one in the list. This might be messy.
An easier algorithm would be to remove everything except the first entry in a group. Then you can simply loop on the file name, removing all instances after the first one.
|
|
|
11-05-2007, 02:35 PM
|
#5
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep: 
|
Re: question about shell script
You are probably not going to find an easy way to do what you want to do in a bash script.
If you are determined to use a script, you will probably have to use Perl, PHP, Python, etc.
I am a programmer, so I would write a C program to do this, but that option is not available to everyone.
|
|
|
All times are GMT -5. The time now is 05:17 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|