convert windows file names

convert windows file names

am 15.04.2005 17:04:02 von James Miller

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-643839312-1113577442=:5717
Content-Type: TEXT/PLAIN; charset="en_US.UTF-8"; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Among various frustrations recently I've had the gratifying success of=20
learning how to use streamripper to augment my music collection.=20
Streamripper is a program that writes an audio stream (e.g., from internet=
=20
radio) to your hard drive as an mp3 file. This is about the closest thing=
=20
to the mythical "Rivo" (Tivo for radio) that currently exists, I think,=20
and could maybe serve as the basis for a *real* Rivo-type program, should=
=20
someone really decide to develop one.

Despite the success, there are some problems--mainly having to do with=20
file names. I've found a nice commercial-free classical (Baroque) station=
=20
and have been happily recording away for the last 24 hrs or so. The=20
streamripper program was evidently written for rock or more popular genres=
=20
and tries to detect breaks between songs so as to make discrete files from=
=20
them. For whatever strange reason, it has a problem detecting beginnings=20
and endings between movements in classical music (despite the noticeable=20
pause) and wants to break between movements about 30 seconds into the next=
=20
movement, rather than at the pause. The cat command seems to fix this,=20
though:

cat movement1.mp3 >full-piece.mp3
cat movement2.mp3 >>full-piece.mp3
cat movement3.mp3 >>full-piece.mp3

The breaks at 30 seconds into the following movement are hardly even=20
noticeable in the full-piece.mp3 (I don't have the kind of purist=20
standards I used to when it comes to audio quality, though).

But, on to file names. unfortunately, the names for the pieces I'm=20
recording from this station follow Windows long-file-naming conventions.=20
Even worse, the names tend to be quite complex and long. Here are a couple=
=20
of examples:

Anton\ Reicha-\ Albert\ Schweitzer\ Quintett\ -\ Wind\ Quintet\ No.9\=20
in\ D\ major\ Op.91\ No.3-\ Finale-\ Allegretto.mp3

Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\=20
Strings\ In\ D\ Major\,\ Op.56£¯5\,\ G411\ -¥².\ Andante\ Come\=20
Prima.mp3

Feeding those names to cat so I can join the movements into a single file=
=20
is going to be a major pain in the wazoo, as they say down at symphony=20
hall. What I was hoping to find is a script that would automatically=20
convert all the wierd characters into more standard Unix file-naming=20
characters. But so far I've come up empty-handed. Can anyone point me to=20
some utility that might do what I need?

As a last resort, I might try to write my own script. I'm not too hot on=20
doing that though, since I'm at an extremely rudimentary level when it=20
comes to script writing. If it comes to that, could someone maybe help me=
=20
get started by giving an example for a script that would do the renaming I=
=20
want? I'd like to retain the bulk of the information, though I don't mind=
=20
truncating words at, say 5 letters. I suppose the main thing would be=20
replaing all the spaces and/or punctuation with dashes and/or underscores.

Thanks, James
--8323328-643839312-1113577442=:5717--
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 17:15:52 von Flemming Greve Skovengaard

James Miller wrote:
> Among various frustrations recently I've had the gratifying success of
> learning how to use streamripper to augment my music collection.
> Streamripper is a program that writes an audio stream (e.g., from
> internet radio) to your hard drive as an mp3 file. This is about the
> closest thing to the mythical "Rivo" (Tivo for radio) that currently
> exists, I think, and could maybe serve as the basis for a *real*
> Rivo-type program, should someone really decide to develop one.
>
> Despite the success, there are some problems--mainly having to do with
> file names. I've found a nice commercial-free classical (Baroque)
> station and have been happily recording away for the last 24 hrs or so.
> The streamripper program was evidently written for rock or more popular
> genres and tries to detect breaks between songs so as to make discrete
> files from them. For whatever strange reason, it has a problem detecting
> beginnings and endings between movements in classical music (despite the
> noticeable pause) and wants to break between movements about 30 seconds
> into the next movement, rather than at the pause. The cat command seems
> to fix this, though:
>
> cat movement1.mp3 >full-piece.mp3
> cat movement2.mp3 >>full-piece.mp3
> cat movement3.mp3 >>full-piece.mp3
>
> The breaks at 30 seconds into the following movement are hardly even
> noticeable in the full-piece.mp3 (I don't have the kind of purist
> standards I used to when it comes to audio quality, though).
>
> But, on to file names. unfortunately, the names for the pieces I'm
> recording from this station follow Windows long-file-naming conventions.
> Even worse, the names tend to be quite complex and long. Here are a
> couple of examples:
>
> Anton\ Reicha-\ Albert\ Schweitzer\ Quintett\ -\ Wind\ Quintet\ No.9\
> in\ D\ major\ Op.91\ No.3-\ Finale-\ Allegretto.mp3
>
> Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\
> Strings\ In\ D\ Major\,\ Op.565\,\ G411\ -.\ Andante\ Come\ Prima.mp3
>
> Feeding those names to cat so I can join the movements into a single
> file is going to be a major pain in the wazoo, as they say down at
> symphony hall. What I was hoping to find is a script that would
> automatically convert all the wierd characters into more standard Unix
> file-naming characters. But so far I've come up empty-handed. Can anyone
> point me to some utility that might do what I need?
>
> As a last resort, I might try to write my own script. I'm not too hot on
> doing that though, since I'm at an extremely rudimentary level when it
> comes to script writing. If it comes to that, could someone maybe help
> me get started by giving an example for a script that would do the
> renaming I want? I'd like to retain the bulk of the information, though
> I don't mind truncating words at, say 5 letters. I suppose the main
> thing would be replaing all the spaces and/or punctuation with dashes
> and/or underscores.
>
> Thanks, Jam
> es

You can use my little perl script for that.

#!/usr/bin/perl


# remove_invalid - Removes invalid characters from filenames.
# Copyright (C) 2004 Flemming Greve Skovengaard
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


# File: remove_invalid
# Version: 0.4.6
# Date (YYYY-MM-DD): 2004-07-24
# Author: Flemming Greve Skovengaard
# Contact: dsl58893@vip.cybercity.dk

## Version 0.1.0
## Date: 2004-04-15
## Replaces spaces with underscores.
##
## Version 0.2.0
## Date: 2004-05-13
## Replaces !, @, $, & (, ), {, }, [, ], <, >, ' and ".
##
## Version 0.3.0
## Date 2004-05-14
## Removes any leading - (minus/dash).
##
## Version 0.4.0
## Date: 2004-05-15
## Added option 'verbose' and 'help'.
## Added 'Files renamed: x'.
##
## Version 0.4.1
## Date: 2004-05-15
## Added option 'version'.
##
## Version 0.4.2
## Date: 2004-05-15
## Removes ,'s (comma).
##
## Version 0.4.3
## Date: 2004-06-29
## Uses File::Basename to get basename if --help
##
## Version 0.4.4
## Date: 2004-07-23
## Simplified substitute procedure.
##
## Version 0.4.5
## Date: 2004-07-23
## Now removes ':' and ';'.
##
## Version 0.4.6
## Date: 2004-08-03
## Correctly removes '!' and '$'.

## Removes all invalid characters in filenames in the current directory.

use strict;
use warnings;
use Getopt::Long;
use File::Basename qw/ basename /;

Getopt::Long::Configure("gnu_getopt");

my ($verbose, $help, $version);
my $current_version = "0.4.6"; # REMEMBER TO UPDATE.
my $dir = '.';
my $num_renamed = 0;

GetOptions('v|verbose' => \$verbose,
'help' => \$help,
'V|version' => \$version,
);

if ($help) {
print "Version: $current_version\n";
print "Usage: ", basename($0), " [-v|--verbose]\n";
exit 0;
}

if ($version) {
print "File:\t\tremove_invalid.pl\n";
print "Version:\t$current_version\n";
print "Written by Flemming Greve Skovengaard.\n";
exit 0;
}

sub rename_file {
my ($old, $new) = @_;

rename $old, $new
or warn "Could not rename '$old' to '$new': $!\n";

return 0;
}

opendir DH, $dir or die "Cannot opendir '$dir': $!\n";

foreach my $file (sort readdir DH) {
my $new_name = $file;
my $rename_failed = 1;

if ($new_name =~ m/(^[-+]|[ (){},'":;<>\!\$\&\@\[\]|])/) {
$new_name =~ s/^[-+]//;
$new_name =~ s/ /_/g;
$new_name =~ s/,/./g;
$new_name =~ s/\@/_at_/g;
$new_name =~ s/\&/_and_/g;
$new_name =~ s/['":;\$\!]//g;
$new_name =~ s/[({<]/_ld_/g;
$new_name =~ s/[)}>]/_rd_/g;
$new_name =~ s/\[/_ld_/g;
$new_name =~ s/\]/_rd_/g;

if ($verbose) {
print "'$file' => '$new_name'\n";
$rename_failed = rename_file($file, $new_name);
}
else {
$rename_failed = rename_file($file, $new_name);
}
++$num_renamed unless $rename_failed;
}
}

print "Files renamed: $num_renamed\n";

--
Flemming Greve Skovengaard FAITH, n.
a.k.a Greven, TuxPower Belief without evidence in what is told
by one who speaks without knowledge,
4112.38 BogoMIPS of things without parallel.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 17:39:43 von Peter Garrett

On Fri, 2005-04-15 at 10:04 -0500, James Miller wrote:
> Among various frustrations recently I've had the gratifying success of
> learning how to use streamripper to augment my music collection.
> Streamripper is a program that writes an audio stream (e.g., from internet
> radio) to your hard drive as an mp3 file. This is about the closest thing
> to the mythical "Rivo" (Tivo for radio) that currently exists, I think,
> and could maybe serve as the basis for a *real* Rivo-type program, should
> someone really decide to develop one.
>
> Despite the success, there are some problems--mainly having to do with
> file names. I've found a nice commercial-free classical (Baroque) station
> and have been happily recording away for the last 24 hrs or so. The
> streamripper program was evidently written for rock or more popular genres
> and tries to detect breaks between songs so as to make discrete files from
> them. For whatever strange reason, it has a problem detecting beginnings
> and endings between movements in classical music (despite the noticeable
> pause) and wants to break between movements about 30 seconds into the next
> movement, rather than at the pause. The cat command seems to fix this,
> though:
>
> cat movement1.mp3 >full-piece.mp3
> cat movement2.mp3 >>full-piece.mp3
> cat movement3.mp3 >>full-piece.mp3
>
> The breaks at 30 seconds into the following movement are hardly even
> noticeable in the full-piece.mp3 (I don't have the kind of purist
> standards I used to when it comes to audio quality, though).
>
> But, on to file names. unfortunately, the names for the pieces I'm
> recording from this station follow Windows long-file-naming conventions.
> Even worse, the names tend to be quite complex and long. Here are a couple
> of examples:
>
> Anton\ Reicha-\ Albert\ Schweitzer\ Quintett\ -\ Wind\ Quintet\ No.9\
> in\ D\ major\ Op.91\ No.3-\ Finale-\ Allegretto.mp3
>
> Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\
> Strings\ In\ D\ Major\,\ Op.565\,\ G411\ -.\ Andante\ Come\
> Prima.mp3
>
> Feeding those names to cat so I can join the movements into a single file
> is going to be a major pain in the wazoo, as they say down at symphony
> hall. What I was hoping to find is a script that would automatically
> convert all the wierd characters into more standard Unix file-naming
> characters. But so far I've come up empty-handed. Can anyone point me to
> some utility that might do what I need?
>
> As a last resort, I might try to write my own script. I'm not too hot on
> doing that though, since I'm at an extremely rudimentary level when it
> comes to script writing. If it comes to that, could someone maybe help me
> get started by giving an example for a script that would do the renaming I
> want? I'd like to retain the bulk of the information, though I don't mind
> truncating words at, say 5 letters. I suppose the main thing would be
> replaing all the spaces and/or punctuation with dashes and/or underscores.
>
> Thanks, James

I just tried this with some mp3 tracks I have here:

cat Really\ Annoying\ File Second Ultra\ Irritating\ File
> testfile.mpg

Seems to work and saves a lot of typing. Of course if you have a large
number of such files even this could get to be a pain, I guess.

By the way, since you like Streamripper, have a look at Streamtuner:

http://www.nongnu.org/streamtuner/

It integrates with Streamripper for click-the-button recording of
streams. Very nice app - the latest version includes a number of sources
as indices, including Xiph, Shoutcast and Live365 as well as a complete
index of your local files, each of these categories having its own tab.

Peter

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 18:37:32 von James Miller

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-1835199109-1113583052=:5717
Content-Type: TEXT/PLAIN; charset="en_US.UTF-8"; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

I tried your perl script and it works really well, Flemming. Thanks for=20
bringing it to my attention. I see it works for all files in a given=20
directory--exactly what I need. Now, in place of something like

Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\ Strings=
\ In\ D\ Major\,\ Op.565\,\ G411\ -.\ Andante\ Come\ Prima.mp3

I get

Patrick_Cohen__and__Mosaiques_Quartet_-_Quintet_For_Piano__a nd__Strings_In_=
D_Major._Op.56£¯5._G411_-¥²._Andante_Come_Prima.mp3

--a big step in the right direction. But I'm still getting some wierd=20
characters in there--£¯ and ¥². Are these unicode or something? Any=
way, I=20
can't reproduce these at the command line. Is there any way your script=20
might be made to catch and replace symbols like these as well (I mean, for=
=20
someone who knows absolutely nothing about Perl, and precious little about=
=20
scripting in general)? I have no idea what information these symbols are=20
supposed to be representing. It's probably so inconsequential I don't even=
=20
need it, so replacing it with virtually any other symbol should suffice.=20
I'd say I've got at least 20 files with such symbols, and more are on the=
=20
way.

Thanks, James
--8323328-1835199109-1113583052=:5717--
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 18:48:46 von Ray Olszewski

At 10:04 AM 4/15/2005 -0500, James Miller wrote:
>Among various frustrations recently I've had the gratifying success of=
=20
>learning how to use streamripper to augment my music collection.=20
>Streamripper is a program that writes an audio stream (e.g., from inte=
rnet=20
>radio) to your hard drive as an mp3 file. This is about the closest th=
ing=20
>to the mythical "Rivo" (Tivo for radio) that currently exists, I think=
,=20
>and could maybe serve as the basis for a *real* Rivo-type program, sho=
uld=20
>someone really decide to develop one.

From looking at the streamripper writeup in the Debian packagins syste=
m,=20
I'd say this is less likely than you think. It says the app is limited =
to=20
MP3 and OGG streams, and these seem to be sonsiderably less popular, wi=
th=20
streaming sources, than WMA, RM, and Shoutcast.

>Despite the success, there are some problems--mainly having to do with=
=20
>file names. I've found a nice commercial-free classical (Baroque) stat=
ion=20
>and have been happily recording away for the last 24 hrs or so. The=20
>streamripper program was evidently written for rock or more popular ge=
nres=20
>and tries to detect breaks between songs so as to make discrete files =
from=20
>them. For whatever strange reason, it has a problem detecting beginnin=
gs=20
>and endings between movements in classical music (despite the noticeab=
le=20
>pause) and wants to break between movements about 30 seconds into the =
next=20
>movement, rather than at the pause. The cat command seems to fix this,=
though:
>
>cat movement1.mp3 >full-piece.mp3
>cat movement2.mp3 >>full-piece.mp3
>cat movement3.mp3 >>full-piece.mp3

>The breaks at 30 seconds into the following movement are hardly even=20
>noticeable in the full-piece.mp3 (I don't have the kind of purist=20
>standards I used to when it comes to audio quality, though).
>
>But, on to file names. unfortunately, the names for the pieces I'm=20
>recording from this station follow Windows long-file-naming convention=
s.=20
>Even worse, the names tend to be quite complex and long. Here are a co=
uple=20
>of examples:
>
>Anton\ Reicha-\ Albert\ Schweitzer\ Quintett\ -\ Wind\ Quintet\ No.9\ =
in\=20
>D\ major\ Op.91\ No.3-\ Finale-\ Allegretto.mp3
>
>Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\=20
>Strings\ In\ D\ Major\,\ Op.56£¯5\,\ G411\ -¥².\ Andante\ Come=
\ Prima.mp3
>
>Feeding those names to cat so I can join the movements into a single f=
ile=20
>is going to be a major pain in the wazoo, as they say down at symphony=
hall.

Yeah. This is the sort of setting where point-and-click GUIs really sho=
w=20
their strength. Windows copes with this sort of gobbledygook just fine,=
and=20
I imagine the heavy-duty Linux GUIs, like KDE and Gnome, do too.

>What I was hoping to find is a script that would automatically convert=
all=20
>the wierd characters into more standard Unix file-naming characters. B=
ut=20
>so far I've come up empty-handed. Can anyone point me to some utility =
that=20
>might do what I need?

OK. A couple of thing to try ... one candidate app plus 2 workaround=20
possibilities.

1. See if the app "mp3wrap" (that's the Debian-Sid package name) helps =
in=20
any way relevant to your problem.

2. Consider using playlists rather than joining the files. If you use x=
mms=20
for playback, it has a deccent GUI for creating playlists, and it has n=
o=20
problem with the "weird" characters. (This naming standard is also a=20
problem for those of us who rip our own CDs to our hard drives as well,=
and=20
xmms plus playlists has always handled it for me.)

3. TAB completion is your friend. Using your first example, I bet somet=
hing=20
close to "Anton" would complete that entry on the command line. Fr=
om=20
the examples you provided, I can't back out where the movement=20
differentiators are in the names, but such things are typically at the =
end=20
of the name, so you might have to entry just a couple of additional=20
characters to complete.

As to actually changing the names ... the problem is that there is no=20
"Unix-friendly" standard for naming music files; the one you are seeing=
has=20
pretty much been adopted universally, at least in the MP3 world (probab=
ly=20
due to the standardizing influence of the CDDB servers, but that's just=
a=20
guess). I know of no off-the shelf script to convert, probably because=20
there is no consensus target for what to convert *to*.

A less targeted solution *might* be to try the app "mmv". (It's just=20
amazing what oddities are lurking around in the Debian packaging system=
) I=20
haven't used it myself, but from the writeup, it might offer you some h=
elp=20
.. though you'll still have to define your own naming convention, so=
a=20
custom script (see below) may be about as easy.

>As a last resort, I might try to write my own script. I'm not too hot =
on=20
>doing that though, since I'm at an extremely rudimentary level when it=
=20
>comes to script writing. If it comes to that, could someone maybe help=
me=20
>get started by giving an example for a script that would do the renami=
ng I=20
>want? I'd like to retain the bulk of the information, though I don't m=
ind=20
>truncating words at, say 5 letters. I suppose the main thing would be=20
>replaing all the spaces and/or punctuation with dashes and/or undersco=
res.

Or just omitting spaces (that's how I name my video files, and the resu=
lt=20
is pretty readable if you are strict about capitalizing every word). As=
ide=20
from spaces, the things you need to get rid of are, almost always,=20
ampersand (&), comma (,), and apostrophe ('). Maybe tilde (~) too. Your=
=20
examples above show a couple of truly weird characters (like the Englis=
h=20
pound and Japanese yen symbols, which I don't even know how to type in=20
here), so you may need a bit more capability than this.

This sort of script wouldn't be too tough to write in Perl, just using =
a=20
few tr commands plus the commands to read and mv file names, and probab=
ly a=20
shell script wouldn't be much tougher. If I have time later, I'll try t=
o=20
cobble something together to serve as an example.

>Thanks, James

Do let us know what solution you end up with ... this is an interesting=
=20
problem.

Closing thought ... take a look at

http://www.classiccat.net/

for another way to acquire (legitimately, as far as I can tell) free MP=
3s=20
of public domain classical recordings. Or try Google; there seems to be=
a=20
lot of this stuff around.


-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"=
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 19:16:03 von mailing-lists

On Fri, 15 Apr 2005, James Miller wrote:

> I tried your perl script and it works really well, Flemming. Thanks f=
or=20
> bringing it to my attention. I see it works for all files in a given=20
> directory--exactly what I need. Now, in place of something like
>=20
> Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\ S=
trings\ In\ D\ Major\,\ Op.565\,\ G411\ -.\ Andante\ Come\ Prima.mp3
>=20
> I get
>=20
> Patrick_Cohen__and__Mosaiques_Quartet_-_Quintet_For_Piano__a nd__Strin=
gs_In_D_Major._Op.56£¯5._G411_-¥²._Andante_Come_Prim a.mp3
>=20
> --a big step in the right direction. But I'm still getting some wierd=
=20
> characters in there--£¯ and ¥². Are these unicode or somethin=
g?=20

To strip or translate characters that can't be printed properly or aren=
't=20
in your locale `man locale' you can use `tr' [translate] from the=20
command-line, for example translate all non-printable characters with
underscores.
~: tr -sc '![:print:]' '_'
translate a `space' to an underscore
~: tr ' ' '_'
DOS to UNIX newlines:
tr -d '\015' < foo.txt > newfoo.txt

or in combi with other programs..
find . -type d -print | xargs rename 'tr/A-Z/a-z/;'=20

If your translating filenames, from the command-line in a sequence
of events, make sure you use `read', that will help reading non-ascii=20
data. `man ascii'

~: ls -1 | while read FNAME ; do echo ${FNAME} | tr ' ' '_' ; done

Most GNU/Linux distro's come with a standaard program called `rename'
~: rename -h
Usage: rename [-v] perlexpr [filenames]

The Bash shell itself has quite some standard easy & powerfull ways onb=
oard
to achive this, named `parameter expansion':=20
ls -1 *.pdf | while read file ; do ps2ascii $file ${file%%pdf}txt ; don=
e
or..
for file in *.bmp ; do convert $file ${file%.bmp}.png ; done

=46rom the bash manual page:
# remove from end the smallest part from `param'
# that equals `word' and returns the remainder as result.
${param%%word}

There are more ways to expand parameters, ${param#word}, ${param##word}=
,=20
${foo:+bar}... Just look in the manual page..

To give an example, in combination with find :
~: find . -name '*.jpg' -print | while read file ; do echo "${file%/*}/=
thumb_${file##*/}" ; done

The unix philosophy is, do one thing and do it good.. Search for `Unix
philosopy' at google to learn more about it. Quite interesting, and wil=
l
give some historical insights and understanding on the command-line.=20

J.

> Anyway, I=20
> can't reproduce these at the command line. Is there any way your scri=
pt=20
> might be made to catch and replace symbols like these as well (I mean=
, for=20
> someone who knows absolutely nothing about Perl, and precious little =
about=20
> scripting in general)? I have no idea what information these symbols =
are=20
> supposed to be representing. It's probably so inconsequential I don't=
even=20
> need it, so replacing it with virtually any other symbol should suffi=
ce.=20
> I'd say I've got at least 20 files with such symbols, and more are on=
the=20
> way.
>=20
> Thanks, James

--
Don't worry Ma'am. We're university students, - we know what we're doin=
g.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"=
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 20:00:53 von chuck gelm net

James Miller wrote:


> But, on to file names. unfortunately, the names for the pieces I'm
> recording from this station follow Windows long-file-naming conventions.
> Even worse, the names tend to be quite complex and long. Here are a
> couple of examples:
>
> Anton\ Reicha-\ Albert\ Schweitzer\ Quintett\ -\ Wind\ Quintet\ No.9\
> in\ D\ major\ Op.91\ No.3-\ Finale-\ Allegretto.mp3
>
> Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\
> Strings\ In\ D\ Major\,\ Op.56??5\,\ G411\ -??.\ Andante\ Come\ Prima.mp3
>
> Feeding those names to cat so I can join the movements into a single
> file is going to be a major pain in the wazoo, as they say down at
> symphony hall. What I was hoping to find is a script that would
> automatically convert all the wierd characters into more standard Unix
> file-naming characters. But so far I've come up empty-handed. Can anyone
> point me to some utility that might do what I need?
>
> As a last resort, I might try to write my own script. I'm not too hot on
> doing that though, since I'm at an extremely rudimentary level when it
> comes to script writing. If it comes to that, could someone maybe help
> me get started by giving an example for a script that would do the
> renaming I want? I'd like to retain the bulk of the information, though
> I don't mind truncating words at, say 5 letters. I suppose the main
> thing would be replaing all the spaces and/or punctuation with dashes
> and/or underscores.
>
> Thanks, Jam
> es

man rename
....
rename " " "_" * # over and over again. ;-)

HTH, Chuck

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 20:17:35 von Flemming Greve Skovengaard

James Miller wrote:
> I tried your perl script and it works really well, Flemming. Thanks for
> bringing it to my attention. I see it works for all files in a given
> directory--exactly what I need. Now, in place of something like
>
> Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\
> Strings\ In\ D\ Major\,\ Op.565\,\ G411\ -.\ Andante\ Come\ Prima.mp3
>
> I get
>
> Patrick_Cohen__and__Mosaiques_Quartet_-_Quintet_For_Piano__a nd__Strings_In_D_Major._Op.565._G411_-._Andante_Come_Prima.m p3
>
>
> --a big step in the right direction. But I'm still getting some wierd
> characters in there-- and . Are these unicode or something? Anyway,
> I can't reproduce these at the command line. Is there any way your
> script might be made to catch and replace symbols like these as well (I
> mean, for someone who knows absolutely nothing about Perl, and precious
> little about scripting in general)? I have no idea what information
> these symbols are supposed to be representing. It's probably so
> inconsequential I don't even need it, so replacing it with virtually any
> other symbol should suffice. I'd say I've got at least 20 files with
> such symbols, and more are on the way.
>
> Thanks, Jam
> es

This should remove the characters in question.

Replace the if-statement with this on:
if ($new_name =~ m/(?:^[-+]|[^-\w.])/ ) {

and add this line below the other $new_name... lines:
$new_name =~ s/[^-\w.]//g;

I have only tested this very little, but the corrections removes anything
that is not a hyphen (-), a word character (A-Za-z_) or a period (.).


--
Flemming Greve Skovengaard FAITH, n.
a.k.a Greven, TuxPower Belief without evidence in what is told
by one who speaks without knowledge,
4112.38 BogoMIPS of things without parallel.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 20:49:09 von James Miller

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-795110782-1113589636=:5717
Content-Type: TEXT/PLAIN; CHARSET="en_US.UTF-8"; FORMAT=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-ID:

Thanks for your input, Ray.

On Fri, 15 Apr 2005, Ray Olszewski wrote:

> 1. See if the app "mp3wrap" (that's the Debian-Sid package name) helps in=
any=20
> way relevant to your problem.

Ok. I'll check that.

> 2. Consider using playlists rather than joining the files. If you use xmm=
s=20
> for playback, it has a deccent GUI for creating playlists, and it has no=
=20
> problem with the "weird" characters. (This naming standard is also a prob=
lem=20
> for those of us who rip our own CDs to our hard drives as well, and xmms =
plus=20
> playlists has always handled it for me.)

In this case, I think cat'ting files together is going to be the right=20
solution, though it might create a bit of extra work. I've discovered that=
=20
it joinsd movments together almost precisely at the point where the break=
=20
was made (ca. 30 seconds into the beginning of a given movement). The=20
breaks are almost unnoticeable when I cat the files together into a single=
=20
file. I'm guessing with a playlist, I'd get a pause at the break, meaning=
=20
I would hear the first 30 seconds of a movement at the end of the=20
preceding movement, then a pause, then a continuation of the movement that=
=20
got cut off by the software. Isn't that how the playlist scenario would=20
work out?

> 3. TAB completion is your friend. Using your first example, I bet somethi=
ng=20
> close to "Anton" would complete that entry on the command line. From=
the=20
> examples you provided, I can't back out where the movement differentiator=
s=20
> are in the names, but such things are typically at the end of the name, s=
o=20
> you might have to entry just a couple of additional characters to complet=
e.

Tab completion only gets me so far, and is less helpful because of all=20
the wierd characters that are getting inserted. For example, "cat Pat"=20
gets me the following output (I include the tail end of the direcory's=20
content from an ls command):

Luigi Boccherini - No. 8 in B flat -- Allegro.mp3
Luigi Boccherini - No. 8 in B flat -- Andante affetuoso.mp3
Luigi Boccherini - No. 9 in F -- Adagio assai.mp3
Luigi Boccherini - No. 9 in F -- Andantino.mp3
Luigi Boccherini - No. 9. in F -- Tempo di minuetto amoroso.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In D Major,=
Op.56£¯5, G411 -¥². Andante Come Prima.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In D Major,=
Op.56£¯5, G411 -¥³. Variazioni.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In D Major,=
Op.56£¯5, G411 -¥°. Andante Sostenuto.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In D Major,=
Op.56£¯5, G411 -¥±. Minuetto Allegro.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In E Minor,=
Op.56£¯1, G407 -¥². Minuetto Con Moto.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In E Minor,=
Op.56£¯1, G407 -¥³. Allegretto Final.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In E Minor,=
Op.56£¯1, G407 -¥±. Adagio.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In E Minor,=
Op.56£¯1, G407 -¥°. Allegro Comodo.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In F Major,=
Op.56£¯2, G408 -¥². Poco Adagio.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In F Major,=
Op.56£¯2, G408 -¥³. Allegretto.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In F Major,=
Op.56£¯2, G408 -¥°. Allegretto.mp3
Patrick Cohen & Mosaiques Quartet - Quintet For Piano & Strings In F Major,=
Op.56£¯2, G408 -¥±. Minuetto Amoroso.mp3
Portland Baroque Orchestra under Monica Huggett, with Richard Savino, baroq=
ue guitar - Concerto In A Major, Op. 30=20
Allegro Maetoso.mp3
Portland Baroque Orchestra under Monica Huggett, with Richard Savino, baroq=
ue guitar - Concerto In A Major, Op. 30=20
Polonaise.mp3
Portland Baroque Orchestra under Monica Huggett, with Richard Savino, baroq=
ue guitar - Concerto In A Major, Op. 30=20
Siciliana.mp3
Portland Baroque Orchestra under Monica Huggett, with Richard Savino, baroq=
ue guitar - Sinfonia Allegro E Con=20
Imperio.mp3
Portland Baroque Orchestra under Monica Huggett, with Richard Savino, baroq=
ue guitar - Sinfonia Allegro.mp3
Portland Baroque Orchestra under Monica Huggett, with Richard Savino, baroq=
ue guitar - Sinfonia Grave.mp3
**ME**@mymachine:~/Classical$ cat Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -=
\ Quintet\ For\ Piano\ \&\ Strings\ In\

As you can see, I have to complete the key, then the opus number, then the=
=20
Yen symbol--etc etc. It's still pretty involved, even using=20
autocompletion. Getting rid of odd characters in file names won't help much=
with=20
that, but it will give me a valid name to use as my full-piece.mp3 file=20
name.

> A less targeted solution *might* be to try the app "mmv". (It's just amaz=
ing=20
> what oddities are lurking around in the Debian packaging system.) I haven=
't=20
> used it myself, but from the writeup, it might offer you some help ... th=
ough=20
> you'll still have to define your own naming convention, so a custom scrip=
t=20
> (see below) may be about as easy.

I'll take a look at that, too.

> This sort of script wouldn't be too tough to write in Perl, just using a =
few=20
> tr commands plus the commands to read and mv file names, and probably a s=
hell=20
> script wouldn't be much tougher. If I have time later, I'll try to cobble=
=20
> something together to serve as an example.

Flemming's has gotten me most of the way. He's just posted a slight=20
modification that may get rid of the rest of the problem characters for=20
me. I'll post to the list whether it works as advertised. If you have the=
=20
time to try a bash script, that would be interesting to see as well.

> Closing thought ... take a look at
>
> http://www.classiccat.net/
>
> for another way to acquire (legitimately, as far as I can tell) free MP3s=
of=20
> public domain classical recordings. Or try Google; there seems to be a lo=
t of=20
> this stuff around.

Another interesting way the internet is turning staid institutions on=20
their ears. I was expecting to see old recordings digitized or something.=
=20
But the little bit of snooping I did there reveals that at least some of=20
these (the Beethoven piano sonata's I was interested in) are private=20
recordings done by unknown (but wanting-to-be-known) artists. It's not=20
going to be Schnabel, but nearly any decent interpretation will suit my=20
needs just fine. The recording industry has not only file sharing to worry=
=20
about, but independents with access to a wide audience without corporate
intermediaries.

James
--8323328-795110782-1113589636=:5717--
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: convert windows file names

am 15.04.2005 21:29:04 von James Miller

Thanks for offering that, Flemming. Modifying the original script per your
directions does, indeed, seem to get rid of the other extraneous
characters. I ran it in a test directory, and the results seem to get just
what I was hoping for. I think I'll go ahead and run it in the real
directory now, where I have probably a couple hundred files in need of
renaming. Great work!

Thanks, James

On Fri, 15 Apr 2005, Flemming Greve Skovengaard wrote:

> This should remove the characters in question.
>
> Replace the if-statement with this on:
> if ($new_name =~ m/(?:^[-+]|[^-\w.])/ ) {
>
> and add this line below the other $new_name... lines:
> $new_name =~ s/[^-\w.]//g;
>
> I have only tested this very little, but the corrections removes anything
> that is not a hyphen (-), a word character (A-Za-z_) or a period (.).
>
>
> --
> Flemming Greve Skovengaard FAITH, n.
> a.k.a Greven, TuxPower Belief without evidence in what is
> told
> by one who speaks without knowledge,
> 4112.38 BogoMIPS of things without parallel.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs