LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-21-2010, 05:50 PM   #16
NirvanaII
Member
 
Registered: Jun 2005
Posts: 139

Original Poster
Rep: Reputation: 18

Code:
path[x]=$(dirname "$(awk NR==$x Musiclist.txt)")
dirname did the job!

Thanks for the assistance grail and smeezekitty!

(i'll mark as SOLVED now, but if you wanna make any suggestions to improve the command go ahead.)
 
Old 06-21-2010, 07:56 PM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well I am kind of curious why the 6 mile long test in the while loop??

I am still reading through it all and will have a suggestion shortly
 
Old 06-21-2010, 08:11 PM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Ok ... so this is untested but seems ok:
Code:
#!/bin/bash

while read line
do
	mfile=$(echo "${line##*/}")
	wfile=$(echo "${mfile%%mp3}wav")
	ffile=$(echo "${mfile%%mp3}flac")
	
	ln -s "$line" "$mfile"
	
	mplayer -cache 32 -ao pcm:file="$wfile" "$mfile"
	lame -V2 "$wfile" "$ffile"
	
	rm -vf *.wav *.mp3
	mv -v "$ffile" $(dirname "$line")
done< <(find "$My_Music" -iname "*.mp3")

Last edited by grail; 06-21-2010 at 10:55 PM.
 
Old 06-21-2010, 10:29 PM   #19
NirvanaII
Member
 
Registered: Jun 2005
Posts: 139

Original Poster
Rep: Reputation: 18
Code:
stuart@stuart:~/music transfer$ ./grail\'s\ script.sh 
./grail's script.sh: line 7: unexpected EOF while looking for matching `)'
./grail's script.sh: line 17: syntax error: unexpected end of file
stuart@stuart:~/music transfer$ cat grail\'s\ script.sh 
#!/bin/bash

while read line
do
	mfile=$(echo "${line##*/}")
	wfile=$(echo "${mfile%%mp3}wav"
	ffile=$(echo "${mfile%%mp3}flac"
	
	ln -s "$line" "$mfile"
	
	mplayer -cache 32 -ao pcm:file="$wfile" "$mfile"
	lame -V2 "$wfile" "$ffile"
	
	rm -vf *.wav *.mp3
	mv -v "$ffile" $(dirname "$line")
done< <(find "$My_Music" -iname "*.mp3")
stuart@stuart:~/music transfer$
???

The mile long test to read it, or the literal test? And looping is all I know, right now.

So... where does the input come from initially here? I can only partially tell as to what's going on. The bit i'd expect first is the last line. Very curious.

(I have quite literally just read a few 'bits' out a loaned library book, and thought i'd make a rough program while dipping in and out of it. My knowledge is scant or rudimentary... whichever the more polite )
 
Old 06-21-2010, 10:58 PM   #20
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Man I am sorry about that, wrote it on the fly and didn't check my closing brackets
I have edited above so if you copy it again it should work (well at least run)

Quote:
So... where does the input come from initially here? I can only partially tell as to what's going on. The bit i'd expect first is the last line. Very curious.
Yeah good question. This considered a here document reference which simply put will return each file from the find and work on each one.

I use the following link as a reference, and as long as you have a little time it can be used by new users too (as it is called Advanced)

tldp.org/LDP/abs/html/
 
Old 06-22-2010, 05:46 PM   #21
NirvanaII
Member
 
Registered: Jun 2005
Posts: 139

Original Poster
Rep: Reputation: 18
I'll take a look through that page when the book is returned.

I hate to say it, but...

Code:
stuart@stuart:~/music transfer$ echo $My_Music
/mnt/sda1/Music/
stuart@stuart:~/music transfer$ ./grail\'s\ script.sh 
find: cannot search `': No such file or directory
The env var works fine:

Code:
stuart@stuart:~/music transfer$ find "$My_Music" -iname "*.mp3" | awk NR==1
/mnt/sda1/Music/Belly/06 - The Bees.mp3
 
Old 06-22-2010, 07:40 PM   #22
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
hmmm ... well you have me a little stumped then???

I just ran the same on my machine after creating the environment variable and changing script to just echo found files and it all worked swimmingly??

Maybe you could comment out the rest and just put an echo of your variable in the script to see if it is seeing it?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
input output error while running 'diff' on a ntfs disk nass Linux - Software 1 12-14-2008 08:56 AM
Arrays of Structures to Arrays of Classes knobby67 Programming 1 01-01-2008 01:39 PM
Arrays - User input - newbie = [ ohfaney Programming 6 05-01-2006 10:14 PM
Question about outputing arrays with pointers, then just arrays... RHLinuxGUY Programming 1 04-12-2006 05:40 AM
Dual Boot diff Hard Disk diff OS on Suse 9.1 wilhem Linux - Newbie 1 08-13-2004 06:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration