LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-22-2009, 07:11 PM   #1
vamped
LQ Newbie
 
Registered: Oct 2006
Posts: 14

Rep: Reputation: 0
cat $(ls -rt) > one_file.mp3 w/ ugly filenames


I want to join several .mp3 files into one file. The files need to be sorted by modification time.

The command
Code:
ls -rt --quoting-style=shell-always
sorts how I need, and quotes the filenames with single quotes.

The command
Code:
cat file1.mp3 file2.mp3 file3.mp3 > one_file.mp3
joins files, generally speaking.

I can combine these into
Code:
cat $(ls -rt) > one_file.mp3
if using simple filenames.

The filenames I'm using though are UGLY and non-uniform, such as

' - --- some (words)- @www.xyz.com --.mp3'

so the command breaks down, and gives an error such as:

cat: unrecognized option '----'

The --quoting-style=shell-always seems not to make a difference in this context.

How could I make this work? A single command is preferable. A short script would be acceptable.

Other Information:
The files are created by recording streaming music. Some stations split songs up into several files, naming them automatically.
 
Old 03-22-2009, 07:19 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
How about:
ls -rt -- | tr '\n' '\0' | xargs -0 cat -- >joined_file.mp3

The double dashes will prevent problems for filenames that start with a dash.
 
Old 03-22-2009, 09:03 PM   #3
vamped
LQ Newbie
 
Registered: Oct 2006
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
How about:
ls -rt -- | tr '\n' '\0' | xargs -0 cat -- >joined_file.mp3

The double dashes will prevent problems for filenames that start with a dash.
Yes! Two neat tricks there: the "--" and the "tr '\n' '\0'"

I don't understand why "ls" would need "--" since the only arguments to it are "-rt". The above solution worked fine for me without it.

I'm also wondering if the output of ls needs to be one file per line in order for tr to null terminate each file name. So:
Code:
ls -rt1
ls -rt1 (rt one) ?

Also thanks for showing me a new way to use xargs. I was used to:
Code:
xargs -0 -I{} command '{}'
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cat in asm/ cat --show-all option Tux Linux - Software 1 09-02-2006 09:31 PM
cat, fifos, and mp3 streams ilikejam Linux - General 4 01-16-2006 11:49 AM
Open Office fonts look ugly (and print ugly too) TheOneAndOnlySM Linux - Software 6 10-17-2003 07:12 PM
'cat' not allowing absolute filenames when piped to 'cut' d3funct Programming 6 12-06-2002 02:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:51 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
Open Source Consulting | Domain Registration