Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-05-2011, 06:27 PM   #1
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 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 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

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

then send this to a script something along the lines of

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

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


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

Old 11-05-2011, 07:10 PM   #2
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:

Old 11-05-2011, 07:19 PM   #3
Registered: May 2001
Posts: 29,390
Blog Entries: 55

Rep: Reputation: 3563Reputation: 3563Reputation: 3563Reputation: 3563Reputation: 3563Reputation: 3563Reputation: 3563Reputation: 3563Reputation: 3563Reputation: 3563Reputation: 3563
Use a "while" loop instead of a "for" one as it would preserve spaces if you properly quote the variable name as in '~/ "${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 you probably could process .flac files and output the .mp3 result to their place in the ~/Netbook/Music/genre/artist/album/ tree?..


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 05:44 AM
piping output of list to cp andy.l Linux - General 3 05-16-2011 06:02 PM
Piping cat output to variable? zizou86 Programming 12 01-13-2010 03:17 PM
Piping output between processes. C. banan Programming 1 11-12-2006 11:25 PM
Piping output to text files corbis_demon Linux - General 3 10-12-2004 03:33 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:50 AM.

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