Re: Rename pictures in the command-line interface

2010-01-05 Thread P.
Ter, 2010-01-05 às 15:35 +0100, herbert langhans escreveu:
 Hi Dario,
 another way is to use batren - its a shell script and should work out of the 
 box on FreeBSD:
 http://batren.sourceforge.net/cgi-bin/blis.cgi/Home
 
 Cheers
 herb langhans

Thank you Herbert, sounds a interesting tool. I'm going to try it.
Now I'm also using Midnight Commander suggested by Polytropon, and that
makes my life alot easer.

More I use FreeBSD, more I like it! :)

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-05 Thread Karl Vogel
 On Mon, 04 Jan 2010 15:52:09 -0500, 
 Nathan Vidican nat...@vidican.com said:

N Personally I find things like this a LOT easier to do in Perl...

   Ditto.  Here's a more generic version which uses regular expressions to
   rename files:
 http://www.pobox.com/~vogelke/src/toolbox/perl/rename.txt

   I put up most of the scripts in my ~/bin directory for examination here,
   if anyone's interested:
 http://www.pobox.com/~vogelke/src/toolbox/

   The descriptions are NOT complete, but they're getting there.

-- 
Karl Vogel  I don't speak for the USAF or my company

The tides are a fight between the Earth and moon.  All water tends
towards the moon, because there is no water in the moon, and nature
abhors a vacuum.  I forget where the sun joins in this fight.
--submitted to science and health teachers, Jr High thru college
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Rename pictures in the command-line interface

2010-01-04 Thread P.
Hello,

I have one directory with some pictures that I wanna rename (I use csh,
don't know if that matters).

For exemple, I have:

b.jpg
bs.jpg
bsd.jpg

And I wanna change to:

bsd1.jpg
bsd2.jpg
bsd3.jpg

I really appreciate if someone can help me. :)

Regards,

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-04 Thread Polytropon
On Mon, 04 Jan 2010 18:02:38 +0100, Dário P. fbsd.questions.l...@gmail.com 
wrote:
 Hello,
 
 I have one directory with some pictures that I wanna rename (I use csh,
 don't know if that matters).
 
 For exemple, I have:
 
 b.jpg
 bs.jpg
 bsd.jpg
 
 And I wanna change to:
 
 bsd1.jpg
 bsd2.jpg
 bsd3.jpg
 
 I really appreciate if someone can help me. :)

I know it's quite ugly and complicatedly written, but maybe
the attached script will help. It just works, but the more
I look at it, the more I wish I hadn't written it, or just
used sh and its printf %03d mechanism. :-)

Keep in mind that the script follows the csh's sorting
order to resolve *, which usually is lexicographical
order.

For example

97.jpg
98.jpg
99.jpg
100.jpg

will, after issuing

renumber bla jpg

result in

bla_01.jpg = 100.jpg
bla_02.jpg = 97.jpg
bla_03.jpg = 98.jpg
bla_04.jpg = 99.jpg

So if you wish to do some file preparation, know that the
powerful Midnight Commander can do this for you (select and
PF6).

Here's the script now. Put it in ~/bin (and add this directory
to your $PATH) as renumber (or any name you like), give it +x
permissions and rehash to make it available to the C shell.
Then, use renumber prefix suffix. It will process ALL
files in the current directory (as I said: ugly as sin).


#!/bin/csh
if ( $1 ==  || $2 ==  ) then
echo Usage: renumber base extension
echoTarget form: base_nn[n].extension
echoFor 1 to 99 files: nn; for more than 99 files: nnn
exit 1
endif

set n = `ls -l | wc | awk '{print $1}'`
set num = `expr $n - 1`
echo ${num} files to handle.

set base = $1
set extn = $2
set n = 0
foreach f ( *.${extn} )
set n = `expr $n + 1`
if ( ${num}  99 ) then
if ( ${%n} == 1 ) then
mv ${f} ${base}_00${n}.${extn}
else if ( ${%n} == 2 ) then
mv ${f} ${base}_0${n}.${extn}
else
mv ${f} ${base}_${n}.${extn}
endif
else
if ( ${%n} == 1 ) then
mv ${f} ${base}_0${n}.${extn}
else
mv ${f} ${base}_${n}.${extn}
endif
endif
end


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-04 Thread P.
Seg, 2010-01-04 às 19:16 +0100, Polytropon escreveu:

 Keep in mind that the script follows the csh's sorting
 order to resolve *, which usually is lexicographical
 order.

The sorting order is not a big problem for me, at least for now. I'm
doing the renaming in one machine with GUI then I upload the pictures to
another machine. The only reason that I need this, is because sometimes
I delete one picture on the other machine and then I have to rename
everything again.

 So if you wish to do some file preparation, know that the
 powerful Midnight Commander can do this for you (select and
 PF6).

Anyway, I gonna look at it.

 Here's the script now. Put it in ~/bin (and add this directory
 to your $PATH) as renumber (or any name you like), give it +x
 permissions and rehash to make it available to the C shell.
 Then, use renumber prefix suffix. It will process ALL
 files in the current directory (as I said: ugly as sin).
 
 
 #!/bin/csh
 if ( $1 ==  || $2 ==  ) then
   echo Usage: renumber base extension
   echoTarget form: base_nn[n].extension
   echoFor 1 to 99 files: nn; for more than 99 files: nnn
   exit 1
 endif
 
 set n = `ls -l | wc | awk '{print $1}'`
 set num = `expr $n - 1`
 echo ${num} files to handle.
 
 set base = $1
 set extn = $2
 set n = 0
 foreach f ( *.${extn} )
   set n = `expr $n + 1`
   if ( ${num}  99 ) then
   if ( ${%n} == 1 ) then
   mv ${f} ${base}_00${n}.${extn}
   else if ( ${%n} == 2 ) then
   mv ${f} ${base}_0${n}.${extn}
   else
   mv ${f} ${base}_${n}.${extn}
   endif
   else
   if ( ${%n} == 1 ) then
   mv ${f} ${base}_0${n}.${extn}
   else
   mv ${f} ${base}_${n}.${extn}
   endif
   endif
 end
 
 

Thanks alot. :)

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-04 Thread Polytropon
On Mon, 04 Jan 2010 20:13:57 +0100, Dário P. fbsd.questions.l...@gmail.com 
wrote:
 The sorting order is not a big problem for me, at least for now. I'm
 doing the renaming in one machine with GUI then I upload the pictures to
 another machine. The only reason that I need this, is because sometimes
 I delete one picture on the other machine and then I have to rename
 everything again.

In this case, pay attention that the renumber script does
not pay attention to not overwrite files. This can lead to
problems when adding files. Let's say you have

pic_01.jpg
pic_02.jpg
pic_03.jpg

and add a file new.jpg, so you have

new.jpg
pic_01.jpg
pic_02.jpg
pic_03.jpg

If you now run

renumber pic jpg

you'll have

pic_01.jpg = new.jpg
pic_02.jpg = pic_01.jpg
pic_03.jpg = pic_02.jpg
pic_04.jpg = pic_03.jpg

and the source pics will be removed, so you end up with

pic_04.jpg = neu.jpg

A workaround is to use the MC to prefix all files with an
arbitrary letter, and THEN run renumber, e. g. select all
(grey *), PF6, to X* (where X is the arbitrary letter)
and have

Xnew.jpg
Xpic_01.jpg
Xpic_02.jpg
Xpic_03.jpg

which can be processed with renumber pic jpg now without
any problems because the existing prefix isn't the same as
the renumbering prefix.

As you see: I have a reason to believe that I should better
write a new script that takes such things into mind and maybe
offer reverse renumbering, overwrite protection and a better
selection which files (instead of hardcoded *) to process.



  So if you wish to do some file preparation, know that the
  powerful Midnight Commander can do this for you (select and
  PF6).
 
 Anyway, I gonna look at it.

It's worth it. The MC is a powerful and still easy to use
tool for file administration.





-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-04 Thread nvidican
No problem. You might also consider extending it to support '.jpeg' as  
well as '.jpg', or even alter to work recursively through  
sub-directories. Like I said though, it's more or less a starting  
point. It will continue to extend beyond the current number each time  
it's run too - so it should never over-write an existing file and  
never need to be altered to support one more digit, (until system  
limitations come in to play - but that's a whole other ball game in  
terms of scale and probably the least of your worries at that point).


Personally I find things like this a LOT easier to do in Perl for the  
power and simplicity of Perls ability to handle and manipulate  
strings, (again like I'd mentioned in my original reply), I'm sure  
this is do-able in a shell script too just seems simpler to  
read/write/work with written in Perl to me and it just gets the job  
done.


--
Nathan Vidican
nat...@vidican.com


Quoting Dário \P. fbsd.questions.l...@gmail.com:


Seg, 2010-01-04 às 14:58 -0500, nvidi...@envieweb.net escreveu:


Dario,

I'm not personally aware of any single commands which allow
substitution using a counter like you're asking, or of a decent way to
do what you're asking from the shell script either; however,
personally I'd write a simple Perl script to do it. The trick being to
be able to find the bsd###.jpg where it left off at in a directory so
you don't overwrite existing files if repeatability is important.

Here's something quick/dirty to work with, you can build from here,
but try copy/pasting the following code into a new Perl script and run
it from withing the directory you want to work:

#!/usr/bin/perl -w


use strict;

my @files = `ls`; # gets a list of all files in the current dir
# start a counter at zero, then increment it below:
my $cntr=0;
# set counter to the largest bsd###.jpg file in this directory:
map { if (/^bsd(\d+)\.jpg/) { $cntr = $1 if($1$cntr); } }
grep(/bsd\d+\.jpg/,@files);

print Left off last time at $cntr, going to start this time at
,++$cntr,.\n;

foreach (@files) {
 chomp();
 # skip all files which are already named bsd###.jpg
 # or are not in ending .jpg
 next if ($_ =~ /bsd\d+\.jpg/ || $_ !~ /(\.jpg)$/i);

 my $new = $_;
 # use a regular expression to substitute the name
 # (note /i == case insensative so it will match '.JPG' as well)
 $new =~ s/^(.+)\.jpg$/bsd$cntr\.jpg/i;

 print Renaming $_ to $new\n;
 # un-comment the line below to actually do the rename:
 # rename($_,$new);
 $cntr++;
}

### END OF SCRIPT ###

An example given a directory with files like:

blah.Jpg
bs432.jpg
bsd11.jpg
bsl.jpg
uh-oh.jpG
yourSelf.JPG

Will give you an output like:

Left off last time at 11, going to start this time at 12.
Renaming blah.Jpg to bsd12.jpg
Renaming bs432.jpg to bsd13.jpg
Renaming bsl.jpg to bsd14.jpg
Renaming uh-oh.jpG to bsd15.jpg
Renaming youSelf.JPG to bsd16.jpg


My $0.02 ... like anything, sure you could do this 100 different other
ways, and sure it's not going to be really efficient for large
volumes, but in a pinch it'll work pretty reliably.

--
Nathan Vidican
nat...@vidican.com




Worked just the way I wanted! :)
Thank you so much for the time you spent doing this Perl script.






___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-04 Thread P.
Seg, 2010-01-04 às 20:59 +0100, Polytropon escreveu:

 As you see: I have a reason to believe that I should better
 write a new script that takes such things into mind and maybe
 offer reverse renumbering, overwrite protection and a better
 selection which files (instead of hardcoded *) to process.

I think I gonna use the Nathan's Perl script, it did the job without any
problem (at least for now :D).

 It's worth it. The MC is a powerful and still easy to use
 tool for file administration.

True. I tried it 5 minutes ago, and I already love it. It's such a nice
tool. :D
Thanks for the tip, and for your time.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-04 Thread nvidican

Quoting Dário \P. fbsd.questions.l...@gmail.com:


Hello,

I have one directory with some pictures that I wanna rename (I use csh,
don't know if that matters).

For exemple, I have:

b.jpg
bs.jpg
bsd.jpg

And I wanna change to:

bsd1.jpg
bsd2.jpg
bsd3.jpg

I really appreciate if someone can help me. :)

Regards,

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org



Dario,

I'm not personally aware of any single commands which allow  
substitution using a counter like you're asking, or of a decent way to  
do what you're asking from the shell script either; however,  
personally I'd write a simple Perl script to do it. The trick being to  
be able to find the bsd###.jpg where it left off at in a directory so  
you don't overwrite existing files if repeatability is important.


Here's something quick/dirty to work with, you can build from here,  
but try copy/pasting the following code into a new Perl script and run  
it from withing the directory you want to work:


#!/usr/bin/perl -w


use strict;

my @files = `ls`; # gets a list of all files in the current dir
# start a counter at zero, then increment it below:
my $cntr=0;
# set counter to the largest bsd###.jpg file in this directory:
map { if (/^bsd(\d+)\.jpg/) { $cntr = $1 if($1$cntr); } }  
grep(/bsd\d+\.jpg/,@files);


print Left off last time at $cntr, going to start this time at  
,++$cntr,.\n;


foreach (@files) {
chomp();
# skip all files which are already named bsd###.jpg
# or are not in ending .jpg
next if ($_ =~ /bsd\d+\.jpg/ || $_ !~ /(\.jpg)$/i);

my $new = $_;
# use a regular expression to substitute the name
# (note /i == case insensative so it will match '.JPG' as well)
$new =~ s/^(.+)\.jpg$/bsd$cntr\.jpg/i;

print Renaming $_ to $new\n;
# un-comment the line below to actually do the rename:
# rename($_,$new);
$cntr++;
}

### END OF SCRIPT ###

An example given a directory with files like:

blah.Jpg
bs432.jpg
bsd11.jpg
bsl.jpg
uh-oh.jpG
yourSelf.JPG

Will give you an output like:

Left off last time at 11, going to start this time at 12.
Renaming blah.Jpg to bsd12.jpg
Renaming bs432.jpg to bsd13.jpg
Renaming bsl.jpg to bsd14.jpg
Renaming uh-oh.jpG to bsd15.jpg
Renaming youSelf.JPG to bsd16.jpg


My $0.02 ... like anything, sure you could do this 100 different other  
ways, and sure it's not going to be really efficient for large  
volumes, but in a pinch it'll work pretty reliably.


--
Nathan Vidican
nat...@vidican.com


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-04 Thread Lowell Gilbert
Dário P. fbsd.questions.l...@gmail.com writes:

 Seg, 2010-01-04 às 20:59 +0100, Polytropon escreveu:

 As you see: I have a reason to believe that I should better
 write a new script that takes such things into mind and maybe
 offer reverse renumbering, overwrite protection and a better
 selection which files (instead of hardcoded *) to process.

 I think I gonna use the Nathan's Perl script, it did the job without any
 problem (at least for now :D).

You might want to look at the jhead port.

It uses the date the picture was taken for the new name, so it's both
stable (i.e., if you run it again you get the same results) and sorts
into proper order.

-- 
Lowell Gilbert, embedded/networking software engineer, Boston area
http://be-well.ilk.org/~lowell/
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Rename pictures in the command-line interface

2010-01-04 Thread P.
Seg, 2010-01-04 às 16:14 -0500, Lowell Gilbert escreveu:
 You might want to look at the jhead port.
 
 It uses the date the picture was taken for the new name, so it's both
 stable (i.e., if you run it again you get the same results) and sorts
 into proper order.

Well, the problem is that some of the pictures that I wanna rename don't
have Exif header (e.g. pictures taken from internet), so it will not
work in this case (I think). And even some pictures I have taken with my
camera that don't have the right date.

That is the why I'm renaming to img1.jpg, img2.jpg, etc.

Quote from jhed website:

-dc Delete comment field from the JPEG header. Note that the comment is
not part of the Exif header.

This is another thing that I was looking for, thanks to you, now I know
how to do it.

Thanks for the tip. :)

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org