From: Rob on
Eef Hartman <E.J.M.Hartman(a)tudelft.nl> wrote:
> Rob <nomail(a)example.com> wrote:
>> 1. put the filenames in a file.
>> find . -name '*.gif' -o -name '*.jpg' -o -name '*.png' -print >/tmp/f
>
> That doesn't work as expected: the -print will "bind" to the last
> -name option and you'll only get the png files in the output.

Well, I never type the -print myself but I included it in fear of people
that would write "you must add -print to that or it will only work with
GNU find and you cannot assume people have that" or similar.

So now I still made a mistake... :-(
From: David Bolt on
On Monday 04 Jan 2010 17:14, while playing with a tin of spray paint,
Rob painted this mural:

<snip>

> Well, I never type the -print myself but I included it in fear of people
> that would write "you must add -print to that or it will only work with
> GNU find and you cannot assume people have that" or similar.
>
> So now I still made a mistake... :-(

Welcome to Usenet. Even if you are correct, someone will be along to
correct you.


Regards,
David Bolt

--
Team Acorn: www.distributed.net OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s
openSUSE 11.0 32b | | openSUSE 11.2 32b |
openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11
From: Vahis on
On 2010-01-04, David Bolt <blacklist-me(a)davjam.org> wrote:
> On Monday 04 Jan 2010 17:14, while playing with a tin of spray paint,
> Rob painted this mural:
>
><snip>
>
>> Well, I never type the -print myself but I included it in fear of people
>> that would write "you must add -print to that or it will only work with
>> GNU find and you cannot assume people have that" or similar.
>>
>> So now I still made a mistake... :-(
>
> Welcome to Usenet. Even if you are correct, someone will be along to
> correct you.
>
>
My original problem has expanded. Maybe I should start another thread?

Anyways, here it is:

I also needed to convert a couple of hundred files,
in 16 sub directories from ogg to mp3.

By searching and pecking (the way I type, too), I came to put this
together:

#!/bin/sh
for x in * ; do mv "$x" `echo -n $x | tr " " "_"`; done
for x in *.ogg ; do sox $x `echo $x|awk -F . '{print $1 ".mp3"}'`; done
find ./ -name '*ogg' -exec rm '{}' ';' -print
for i in ./* ; do
if [[ `echo "$i" | grep -r '_' | grep -v 'm3u'` ]]
then
mv "$i" "`echo "$i" | sed 's/_/\ /g' | perl -p -e
's/(\\w+)/\\u\\L$1/g;' | sed 's/Mp3/mp3/g'`";
# echo "`echo "$i" | sed 's/_/\ /g' | perl -p -e
# 's/(\\w+)/\\u\\L$1/g;' | sed 's/Mp3/mp3/g'`";
fi
done


In the above, first the files look like this:

04 Between The Devil And The Deep Blue Sea.ogg

I wasn't able to convert without first changing the spaces to
underscores, so I added the first line to the script. So they go:

04_Between_The_Devil_And_The_Deep_Blue_Sea.mp3

The second line converts them, the renamed ogg files is still there,
the third line removes them.

After the rest the files look like:

04 Between The Devil And The Deep Blue Sea.mp3

This is exactly how I wanted them.
I was trying to make this recursive. It is, partly. If it's run in the
parent, it removes everything in the end from the sub directories.

But when it's run in the actual directory, it works fine.

It's been put together of pieces that I found with luck mostly.
I've worked around the lack of recursiveness this time but it would be
nice to have it working properly for future purposes...

Vahis
--
"Sunrise 9:25am (EET), sunset 3:25pm (EET) at Espoo, FI (6:00 hours daylight)"
http://waxborg.servepics.com
Linux 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64
7:41pm up 66 days 0:42, 12 users, load average: 0.68, 0.82, 0.64
From: David Bolt on
On Monday 04 Jan 2010 18:17, while playing with a tin of spray paint,
houghi painted this mural:

> David Bolt wrote:
>> Welcome to Usenet. Even if you are correct, someone will be along to
>> correct you.
>
> That is not always the case. (Neither the first nor the second
> sentence.) ;-)

LOL


Regards,
David Bolt

--
Team Acorn: www.distributed.net OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s
openSUSE 11.0 32b | | openSUSE 11.2 32b |
openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11
From: David Bolt on
On Monday 04 Jan 2010 18:13, while playing with a tin of spray paint,
Vahis painted this mural:

> By searching and pecking (the way I type, too), I came to put this
> together:
>
> #!/bin/sh
> for x in * ; do mv "$x" `echo -n $x | tr " " "_"`; done
> for x in *.ogg ; do sox $x `echo $x|awk -F . '{print $1 ".mp3"}'`; done
> find ./ -name '*ogg' -exec rm '{}' ';' -print
> for i in ./* ; do
> if [[ `echo "$i" | grep -r '_' | grep -v 'm3u'` ]]
> then
> mv "$i" "`echo "$i" | sed 's/_/\ /g' | perl -p -e
> 's/(\\w+)/\\u\\L$1/g;' | sed 's/Mp3/mp3/g'`";
> # echo "`echo "$i" | sed 's/_/\ /g' | perl -p -e
> # 's/(\\w+)/\\u\\L$1/g;' | sed 's/Mp3/mp3/g'`";
> fi
> done
>
>
> In the above, first the files look like this:
>
> 04 Between The Devil And The Deep Blue Sea.ogg
>
> I wasn't able to convert without first changing the spaces to
> underscores, so I added the first line to the script. So they go:
>
> 04_Between_The_Devil_And_The_Deep_Blue_Sea.mp3
>
> The second line converts them, the renamed ogg files is still there,
> the third line removes them.
>
> After the rest the files look like:
>
> 04 Between The Devil And The Deep Blue Sea.mp3
>
> This is exactly how I wanted them.

First tip, quote your variables then you won't have issues with spaces
or other characters in the file name, which means no need for the first
loop.

Second tip, using bash substitution means no need for a big chunk of
the second loop.

Third, the find command will find all "*ogg" files and remove them.
This could result in music files that haven't been converted being
removed.

My suggestion would be to replace those three lines using this single
line:

for x in *.ogg ; do sox "${x}" "${x%.ogg}.mp3" && rm "${x}" ; done

It will remove each .ogg file after a successful conversion.

> I was trying to make this recursive. It is, partly. If it's run in the
> parent, it removes everything in the end from the sub directories.
>
> But when it's run in the actual directory, it works fine.
>
> It's been put together of pieces that I found with luck mostly.
> I've worked around the lack of recursiveness this time but it would be
> nice to have it working properly for future purposes...

This is untested, but should work. For testing purposes, the removal is
commented out. After some testing, you can un-comment it.

#!/bin/bash

find -type f -name "*.ogg" | \
while read SOURCE
do

# store the directory part of the file name
#
DIR="${x%/*}"

# hold just the file name, ignoring the rest of the path
# also strip off the .ogg
#
NAME="${SOURCE##*/}"
NAME="${NAME%.ogg}"

# replace any '_' with spaces
#
NAME="${NAME//_/ }"

# now uppercase the words
#
NAME=$(echo "${NAME}"| perl -p -e 's/(\w+)/\u\L$1/g;')

# finally, do the conversion
#
sox "${SOURCE}" "${DIR}/${NAME}.mp3" #&& rm "${SOURCE}"

done

exit 0


Regards,
David Bolt

--
Team Acorn: www.distributed.net OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s
openSUSE 11.0 32b | | openSUSE 11.2 32b |
openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11