LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 11-05-2011, 07:27 PM   #1
TwinReverb
Member
 
Registered: Sep 2008
Location: Misawa AB, Japan
Distribution: Slackware
Posts: 191
Blog Entries: 2

Rep: Reputation: 40
Having issues with piping output


OK, my issue is I have ~/Music/$genre/$artist/$album/$song type music stash where I have FLAC files and 320k bit MP3s (think Amazon.com). I was trying to create a script that would take this exactly as is (entire tree and files) to ~/Netbook/Music and then either run flac2mp3.sh on the flac files and/or transcode the mp3's into a lower bit rate because I have a netbook that has very little storage space. So I was thinking start with the output of

#PWD=~/Music
find . -type d | sed 's/.\///' # this is the "skeleton of directory structure

then send this to a script something along the lines of

#PWD=~/Netbook/Music
# This already has the same $genre/$artist/$album directories created
for i in $(find . -type d | sed 's/.\///')
do
cp ~/Music/"$i"/* ~/Netbook/Music/"$i"
for j in ~/Netbook/Music/"$i"/*.flac
do
~/flac2mp3.sh "$j"
done
for j in ~/Netbook/Music/"$i"/*.mp3
do
ffmpeg -i "$j" -ab 128k tmp.mp3
rm "$i"
mv tmp.mp3 "$i"
done
done

But the problem is the output of find (which I use sed to remove the ./ from the beginning of) seems to get lost in translation, i.e. when I use an echo command to check the output of it, I notice that directories with spaces in their names become multiple inputs rather than one single input, so the command would never work because I get stuff like

No/*
Line/*
On/*
The/*
Horizon/*

Etc you get my point. Is there a more elegant and effective way to try to do this?

V/R,
Robert
 
Old 11-05-2011, 08:10 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
try: find -d -print0 | ...

or set IFS to newline char at start of script, like:

IFS="
"
 
Old 11-05-2011, 08:19 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
Use a "while" loop instead of a "for" one as it would preserve spaces if you properly quote the variable name as in '~/flac2mp3.sh "${ITEM}";'. (Also note 'cp' has "--parents"?) Also copying a complete .flac file tree doesn't make much sense here: with a wee bit of modification of flac2mp3.sh you probably could process .flac files and output the .mp3 result to their place in the ~/Netbook/Music/genre/artist/album/ tree?..
 
  


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
[SOLVED] piping date output qrange Linux - Newbie 1 07-21-2011 06:44 AM
piping output of list to cp andy.l Linux - General 3 05-16-2011 07:02 PM
Piping cat output to variable? zizou86 Programming 12 01-13-2010 04:17 PM
Piping output between processes. C. banan Programming 1 11-13-2006 12:25 AM
Piping output to text files corbis_demon Linux - General 3 10-12-2004 04:33 AM

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

All times are GMT -5. The time now is 09:44 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration