You are not logged in.

#1 2009-02-03 21:09:32

fiod
Member
Registered: 2007-04-02
Posts: 205

A simple scripting question

Hi,

I've got tons of MP3 files with ISO8859-8 id3 tags. I want to convert them all to Unicode.

I've made a list of all the MP3 files in a file called "templist".

I've converted all spaces " " to "\ " in the file using sed, and added " at the end and the begining of every line.

The program mp3unicode is used to convert id3 tags. The program's syntax is:
mp3unicde <myoptions> file1 file2 file3 ...

How do I "cat" the "templist" file at the end of the mp3unicode command?

None of these worked:

cat templist | mp3unicde <..>
or
mp3unicde <..> `cat templist`

Thanks a lot,
fiod

Offline

#2 2009-02-03 21:15:30

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: A simple scripting question

mp3unicde <myoptions> $(cat templist) should work, but so should the backticks version. What error did you get with backticks?

Another option if you're in a hurry is to just put mp3unicde <myoptions> at the front of your list of files, replace all newlines with spaces, and then execute the file with sh <filename>

Or you could echo the lines in a for loop and run mp3unicde for each one.

Last edited by Dusty (2009-02-03 21:16:45)

Offline

#3 2009-02-03 21:20:41

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: A simple scripting question

Not sure what the problem is, but a simple loop like this should work:

#!/bin/sh
for i in `cat templist`; do
    mp3unicde [options] "$i"
done

If you do it this way then you don't have to do any fancy thing to the templist file -- no quotes necessary and you don't need to do anything special about the spaces, etc.

Offline

#4 2009-02-03 21:27:28

fiod
Member
Registered: 2007-04-02
Posts: 205

Re: A simple scripting question

Hi,

Thanks a lot for the replies.

I'll check the solutions.

Thanks again,
fiod

Offline

#5 2009-02-03 21:30:39

fiod
Member
Registered: 2007-04-02
Posts: 205

Re: A simple scripting question

fwojciec wrote:

Not sure what the problem is, but a simple loop like this should work:

#!/bin/sh
for i in `cat templist`; do
    mp3unicde [options] "$i"
done

If you do it this way then you don't have to do any fancy thing to the templist file -- no quotes necessary and you don't need to do anything special about the spaces, etc.

The filenames contain spaces, thus this solution doesn't work.

Can you think of how to change this, so that the "$i" will contain the entire file name every iteration?

Thanks
fiod

Offline

#6 2009-02-03 21:35:04

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: A simple scripting question

fiod wrote:
fwojciec wrote:

Not sure what the problem is, but a simple loop like this should work:

#!/bin/sh
for i in `cat templist`; do
    mp3unicde [options] "$i"
done

If you do it this way then you don't have to do any fancy thing to the templist file -- no quotes necessary and you don't need to do anything special about the spaces, etc.

The filenames contain spaces, thus this solution doesn't work.

Can you think of how to change this, so that the "$i" will contain the entire file name every iteration?

Thanks
fiod

The spaces are not going to be a problem, since $i variable is contained inside quotes.
The loop will basically take a line at the time from the templist file and give it as an argument to mp3unicde tool -- it will iterate like this through the entire templist file.

Last edited by fwojciec (2009-02-03 21:37:19)

Offline

#7 2009-02-03 21:42:17

fiod
Member
Registered: 2007-04-02
Posts: 205

Re: A simple scripting question

fwojciec wrote:
fiod wrote:
fwojciec wrote:

Not sure what the problem is, but a simple loop like this should work:

#!/bin/sh
for i in `cat templist`; do
    mp3unicde [options] "$i"
done

If you do it this way then you don't have to do any fancy thing to the templist file -- no quotes necessary and you don't need to do anything special about the spaces, etc.

The filenames contain spaces, thus this solution doesn't work.

Can you think of how to change this, so that the "$i" will contain the entire file name every iteration?

Thanks
fiod

The spaces are not going to be a problem, since $i variable is contained inside quotes.
The loop will basically take a line at the time from the templist file and give it as an argument to mp3unicde tool -- it will iterate like this through the entire templist file.

Thanks for the reply.

Example:
This is the text file:

aa bb
cc dd
ee ff

This is the script:

#!/bin/sh
for i in `cat done`; do
    #mp3unicode -s iso8859-8 -2 unicode "$i"
        echo "$i"
done

This is the output:

[fio@lgtux /tmp/example]$ ./sc
aa
bb
cc
dd
ee
ff
[fio@lgtux /tmp/example]$

This means that the "$i" doesn't work as expected. right?

Thanks again,
fiod

Offline

#8 2009-02-03 21:51:46

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: A simple scripting question

You're right.
The loop should look like this:

#!/bin/sh
for i in "`cat templist`"; do
    mp3unicde [options] "$i"
done

EDIT: Or this:

#!/bin/sh
cat templist | while read N
do
    mp3unicde [options] "$N"
done

Last edited by fwojciec (2009-02-03 22:01:08)

Offline

#9 2009-02-03 22:11:37

fiod
Member
Registered: 2007-04-02
Posts: 205

Re: A simple scripting question

fwojciec wrote:

You're right.
The loop should look like this:

#!/bin/sh
for i in "`cat templist`"; do
    mp3unicde [options] "$i"
done

EDIT: Or this:

#!/bin/sh
cat templist | while read N
do
    mp3unicde [options] "$N"
done

Hey,

Thanks a lot for all the help.
Still no luck:

When typing:

mp3unicode -s iso8859-8 "./Cranberries/The Cranberries - Analyse - 01 Linger (live).mp3"

everything works great.

The file t2 is:

"./Cranberries/The Cranberries - Analyse - 01 Linger (live).mp3"
"./Cranberries/The Cranberries - No Need to Argue - 01 Ode to My Family.mp3"

and when issuing the script, which is:

#!/bin/sh
for i in "`cat t2`"; do
    mp3unicode -s iso8859-8 -2 unicode "$i"
#       echo "$i"
done

i get:

[fio@lgtux /tmp/ex2]$ ./sc
Error: Cannot open file: "./Cranberries/The Cranberries - Analyse - 01 Linger (live).mp3"
"./Cranberries/The Cranberries - No Need to Argue - 01 Ode to My Family.mp3".
[fio@lgtux /tmp/ex2]$

Any suggestions?

Thanks
fiod

Offline

#10 2009-02-03 22:15:23

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: A simple scripting question

Maybe the quotes in the t2 file are causing the problems -- they shouldn't be needed in either case...

Also, since the files specified in t2 file start with ./* you have to make sure that you are in the correct directory.  You can add "cd /directory/with/music/files" at the beginning of the script, before the loop.

Offline

#11 2009-02-03 22:17:27

fiod
Member
Registered: 2007-04-02
Posts: 205

Re: A simple scripting question

fwojciec wrote:

Maybe the quotes in the t2 file are causing the problems -- they shouldn't be needed in either case...

Also, since the files specified in t2 file start with ./* you have to make sure that you are in the correct directory.  You can add "cd /directory/with/music/files" at the beginning of the script, before the loop.

Checked both..

I've tried the script without "" in the t2 file, and made sure that I am in the corrent directory.

Still no luck...

Offline

#12 2009-02-03 22:20:06

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: A simple scripting question

Strange.

Maybe an alternative approach is required.  What about using find?  Something like this:

#!/bin/sh
find /path/to/music/files -type f -name *.mp3 | while read N
do
    mp3unicde [options] "$N"
done

Careful, because this will also recurse into directories within the specified directory.

Offline

#13 2009-02-03 22:30:15

fiod
Member
Registered: 2007-04-02
Posts: 205

Re: A simple scripting question

fwojciec wrote:

Strange.

Maybe an alternative approach is required.  What about using find?  Something like this:

#!/bin/sh
find /path/to/music/files -type f -name *.mp3 | while read N
do
    mp3unicde [options] "$N"
done

Careful, because this will also recurse into directories within the specified directory.

Worked like a charm.

I wonder why the previous version did not work.

Thanks a lot!

fiod

Offline

#14 2009-02-03 22:39:14

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: A simple scripting question

I'm glad it worked smile

Offline

Board footer

Powered by FluxBB