[nSLUG] Removing spaces from file names - note, long lines

Vlado Keselj vlado at dnlp.ca
Wed Nov 12 22:32:15 AST 2014


This one-liner does not do the same operation.  My main goal was 
to turn one or any chosen filenames that look like:

Joe, Jack & Jane's document (version # 1) [draft].doc

into something like:

Joe--Jack_and_Jane-s_document_-version_=23_1-_-draft-_.doc



On Wed, 12 Nov 2014, Eugene Cormier wrote:

> wow, you guys really have complicated scripts to do this, I've always
> used simple bash one-liners:
> for f in * ; do mv "$f" `echo $f | tr ' ' '_'`; done
> 
> Eugene
> 
> On Wed, Nov 12, 2014 at 09:29:40PM -0400, Vlado Keselj wrote:
> > 
> > Sorry... it seems that the focus of the thread drifted away from the 
> > original topic.  My reply was intended for the original task.
> > 
> > 
> > On Wed, 12 Nov 2014, Vlado Keselj wrote:
> > 
> > > 
> > > Interesting that so many people need this similar utility.  I have been 
> > > using my Perl script fix-file-names.pl.  I tried to fix the file names in 
> > > a way that look reasonable to me, and yet not to loose too much 
> > > information:
> > > 
> > > #!/usr/bin/perl
> > > # Author: Vlado Keselj 2009-14 last update 2014-04-25
> > > # Change file names to safe names (e.g., space to _)
> > > 
> > > for my $fnold (@ARGV) {
> > >     my $fnnew = $fnold;
> > > 
> > >     local $_ = $fnnew; s/ +- +/-/g;
> > >     s/''+/--/g; s/'/-/g; s/[[(<{]/_-/g; s/[])>}]/-_/g;
> > >     s/[,:;]\s*/--/g; s/&/and/g; s/ /_/g;
> > >     s/__+/_/g; s/---+/--/g;
> > >     s/\xE2\x80\x99/-/g; # Single right quote
> > >     s/(=|[^\w.-])/"=".uc unpack("H2",$1)/ge;
> > >     $fnnew=$_;
> > > 
> > >     if ($fnnew eq $fnold) { print "$fnnew \t\tthe same file name kept!\n" }
> > >     else {
> > > 	if (-e $fnnew) { die "$fnnew already exists!" }
> > > 	print "$fnold \t-> $fnnew\n";
> > > 	rename($fnold,$fnnew) or die;
> > >     }
> > > }
> > > 
> > > Regards,
> > > Vlado
> > > 
> > > 
> > > On Wed, 12 Nov 2014, Oliver Doepner wrote:
> > > 
> > > > I use exiftool because it can deal with video files as well as picture files:
> > > > http://dev.exiv2.org/projects/exiv2/wiki/How_does_Exiv2_compare_to_Exiftool
> > > > http://www.exiv2.org/manpage.html
> > > > 
> > > > On Wed, Nov 12, 2014 at 3:29 PM, Jack Warkentin <jwark at bellaliant.net> wrote:
> > > >       Hi Everybody
> > > > 
> > > >       exiv2 ( http://www.exiv2.org/ ) is another command line utility for extracting and writing exif data to/from
> > > >       jpeg image files. I use it for writing location and caption information into the pictures I have taken, and
> > > >       then displaying the information back in a nice format. On Debian, it is available as a package with that
> > > >       name.
> > > > 
> > > >       Regards
> > > > 
> > > >       Jack
> > > > 
> > > > 
> > > >       Mike Spencer wrote:
> > > > 
> > > >             Oliver Doepner<odoepner at gmail.com>  wrote:
> > > > 
> > > >                   Regarding moving photo files, I use a script that utilizes exiftool
> > > >                   to determine year and month the photo (or video) was taken and moves
> > > >                   it to a yyyy/mm folder:
> > > > 
> > > >                   https://odoepner.wordpress.com/2014/01/11/organize-image-and-video-files-by-creation-date-with-exiftool/
> > > > 
> > > > 
> > > >             Interesting.  I've used wrjpgcom(1) to add metadata to jpegs although
> > > >             that feature of jpeg seems to be little used elsewhere.
> > > > 
> > > >             I don't have exiftool (just fetched it from the net) although I see
> > > >             from strings(1) that the date for many photos is there in a header
> > > >             field of some kind.  I gather, from glancing over the EXIF standard
> > > >             (MEGO), that EXIF is built on top of TIFF?  I once commenced trying to
> > > >             beat up the TIFF libs with a view to writing my own image manipulation
> > > >             code.  It wasn't very long before I decided that I didn't care enough
> > > >             about it to grovel through all the defines, typedefs and other
> > > >             indirection to the required extent.
> > > > 
> > > >             So I have a new tool to play with, thanks.  Although I'm not sure I'll
> > > >             have much need for most of the capabilities.
> > > > 
> > > > 
> > > >             - Mike
> > > > 
> > > > 
> > > >       --
> > > >       Jack Warkentin, phone 902-404-0457, email jwark at bellaliant.net
> > > >       39 Inverness Avenue, Halifax, Nova Scotia, Canada, B3P 1X6
> > > >       _______________________________________________
> > > >       nSLUG mailing list
> > > >       nSLUG at nslug.ns.ca
> > > >       http://nslug.ns.ca/mailman/listinfo/nslug
> > > > 
> > > > 
> > > > 
> > > > 
> > > > --
> > > > Oliver Doepner
> > > > Software Engineer
> > > > http://oliver.doepner.net/
> > > > 
> > > > 
> 
> > _______________________________________________
> > nSLUG mailing list
> > nSLUG at nslug.ns.ca
> > http://nslug.ns.ca/mailman/listinfo/nslug
> 
> 
> -- 
> Eugene Cormier
> ---------------
> Full-time Instructor
> Acadia University
> www.eugenecormier.com
> eugenecormier at gmail.com
> Office: Denton Hall Rm.235
> Office Hours: Monday & Wednesday 10:30-11:30 (or by appointment)
> Phone: (902) 585-1329
> 
> 
> ---------------
> Statement of Confidentiality
> This message (including attachments) may contain confidential or
> privileged information intended for a specific individual or
> organization. If you have received this communication in error, please
> notify the sender immediately. If you are not the intended recipient,
> you are not authorized to use, disclose, distribute, copy, print or rely
> on this email, and should promptly delete this email from your entire
> computer system.
> 
> _______________________________________________
> nSLUG mailing list
> nSLUG at nslug.ns.ca
> http://nslug.ns.ca/mailman/listinfo/nslug
> 


More information about the nSLUG mailing list