Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Merge MP3 files with the Unix command cat UNIX
Use cat to merge chapters of an audiobook or other multipart files you may prefer to consolidate. You might proceed as follows:
  1. Create a temporary directory for the files to concatenate
  2. cd to the directory in Terminal
  3. Use the wildcard (*) to merge the files in the order in which they appear in the directory, and > redirection to create a single file, e.g.:
    
     % cat * > xxx.mp3
    
If you've got a heap of files and don't feel like mousing, set up a subfolder as the working directory inside the folder with the files to concatenate. You can then wildcard the files to the working directory subfolder with something like this:

 % mv ../abc* ./
When finished, move the merged file to the parent directory with mv xxx.mp3 ../, then delete the parts in the working directory with rm *. It's a good idea to back up the files before you begin -- otherwise, you may rm away your material inadvertently.
    •    
  • Currently 3.38 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (13 votes cast)
 
[69,407 views]  

Merge MP3 files with the Unix command cat | 20 comments | Create New Account
Click here to return to the 'Merge MP3 files with the Unix command cat' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Watch those ID3 tags!
Authored by: aramis on Feb 12, '04 11:49:08AM

Keep in mind that you'll be merging your ID3 tags together too. If you have a tool to strip all tags before you cat them together, you'll be in better shape, standards speaking.

Pretty much all modern players know to ignore garbage in the middle of the file, but some older (especially hardware based) players may either chirp when they get to the merge points or just stop playing all together.

If you're merging tracks that lived in iTunes, odds are there's an ID3v1.x tag on the end of each track (128 bytes long) and an ID3v2.x tag on the front which could be several KB if there's album art, lyrics, or any of the longer IDv2 elements included.



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: Greedo on Feb 12, '04 11:52:42AM
If the files aren't in the proper order in your directory, you can merge them manually as well:

cat first_part.mp3 > newfile.mp3
cat second_part.mp3 >> newfile.mp3
cat third_part.mp3 >> newfile.mp3
Note that the first command uses > which just redirects the output to a file (overwriting it if it already exists). Subsequent commands use >> which appends the data to the end of the file. Basic Unix stuff, but handy nevertheless!

[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: c8h10n4o2 on Feb 12, '04 12:10:32PM

Or you can just say:

cat first_part.mp3 second_part.mp3 third_part.mp3 > newfile.mp3

all on one line.



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: DougAdams on Feb 12, '04 01:00:05PM
Track Splicer is an AppleScript for iTunes that automates the joining of audio files with cat.

[ Reply to This | # ]
How about splitting?
Authored by: jjgb on Feb 12, '04 04:00:44PM

What I would really like is some way of splitting a long mp3 into several tracks. Does anyone know how to do this? So far I've only found PC programs that do it... so it's a no go.



[ Reply to This | # ]
How about splitting?
Authored by: jakacmar on Feb 12, '04 06:28:02PM

You can split an MP3 track using any number of programs. The first to spring to mind is QuickTime Pro. Open the long MP3, select only the area you want, copy, paste it in a new player and save it. Repeat for all "segments".



[ Reply to This | # ]
How about splitting?
Authored by: lipids on Feb 12, '04 06:39:32PM

Just about any audio editing app will do this. A few suggestions for you:

Audacity
Peak LE
Spark ME
Garageband
I bet iMovie might work also.



[ Reply to This | # ]
How about splitting?
Authored by: gidds on Feb 12, '04 08:49:05PM
Ah, but those all involve decompressing the MP3 and then recompressing it after editing, which is slow and loses quality.

The only app I've seen which lets you edit MP3s without decompressing them is MP3 Trimmer, but I've never used it myself.

---

Andy/

[ Reply to This | # ]

How about splitting?
Authored by: DougAdams on Feb 12, '04 07:14:33PM
Amadeus II is an awesome audio file editor for $25.

[ Reply to This | # ]
How about splitting?
Authored by: godo on Feb 13, '04 01:23:42AM

If all you want to do is split a large mp3 into segments of fixed size (say, 2 minutes), try Xmp3split.



[ Reply to This | # ]
Other File Types?
Authored by: jakacmar on Feb 12, '04 06:31:11PM

I know that cat also works with text files, but what other file types can be merged by simply using cat and still remain usable (e.g., movie files, etc.) If anyone knows about this I'm very curious.



[ Reply to This | # ]
Other File Types?
Authored by: pembery on Feb 13, '04 06:03:21AM

I use 'cat' to join quicktime movies all the time. If I have a movies that will not fit on a single CD then I split them using the 'split' command to burn them and then join them back together using 'cat':

cat file1 file2 file3 > outputfile.mov



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: bdm on Feb 12, '04 09:41:09PM

Warning, very dangerous practice!

The command
cat * >xx
when executed using tcsh, first creates the file xx, then
expands "*" to include xx, then does the copy. The contents
of xx will be copied into itself forever. I just made a 100 MB file
in a few seconds that way.

In bash, apparently "*" is expanded before xx is created, but if
xx already exists the same disastrous copy-to-self happens.

A better way is to place the output somewhere else temporarily:
cat * >/tmp/xx ; mv /tmp/xx .
Alternatively, replace "*" by a pattern that more explicitly identifies
the input files without matching the output file.

Brendan.



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: dogen on Feb 13, '04 05:22:20PM
Thanks for the caveat, Brendon, and sorry the hint ran wild. Another option:
cat * > ../xxx
That puts the merged file in a parent directory to avoid the tcsh endless loop. Incidentally, though perhaps too basic to mention, note that enclosing the filename in quotation marks allows for long names, as in "xxx yyy zzz.mp3"

[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: cynikal on Feb 13, '04 05:30:33PM

but do your programs also query cddb for split points and auto-split accordingly too?

mp3splt

nuff said..



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: jackal242 on Mar 26, '10 11:21:29AM

This hint does NOT WORK AT ALL for mp3 files that are of different bit rates.

If you song1.mp3 is of 128 bitrate and song2.mp3 is of 160 bitrate and you try to merge them using cat then it will fail to play the second song.

All the tracks must be of the same bitrate for this hint to work.



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: ekl on May 31, '10 05:08:10PM

That shit was FAST.

I almost thought it didn't work because it finished in less than a second, but the resulting mp3 plays fine.

Now I feel like an idiot for spending half an hour in Audacity doing essentially the same thing earlier today.



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: dcottle on Nov 23, '10 09:06:45PM

I've been looking for a way to join aif files and have tried this a number of different ways (cat file1.aif file2.aif >> file3.aif, and cat file1.aif > file3.aif ; cat file2.aif >> file3.aif), and while the resulting file is the expected size, when I open it (in Amadeus Pro) it only shows the content from the first file. Do I have to ignore the header of the second file? There is no such option in cat.

I tried it with rtf files with the same results. The content from the second file is missing. It worked with an ls command (ls > file1 ; man cat > file2 ; cat file1 file2 >> file3). What am I doing wrong that it won't work with .aif or .rtf?



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: m5m on Dec 17, '10 06:53:28PM

There's something wrong with the concatenated file as you suggest dcottle, but I don't know what it is. Neither iTunes nor Quicktime can see past the first file's length in the resulting file. If I open that file in Fission, then save over the audio without changing anything, THAT file is readable normally by quicktime/iTunes. It's my best workaround for the problem that I don't have the expertise to fathom. Any expert tweeks to this thread to make it not suffer from this serious problem would be appreciated. I'm unable to understand how it could work effectively for anyone... Perhaps it's a more recent version of quicktime that's not reading the headers the way it used to???



[ Reply to This | # ]
Merge MP3 files with the Unix command cat
Authored by: ragmaxone on Dec 01, '13 12:40:17PM

cat doesn't work, the file isn't readable in iTunes, it just reads the first file, certainly a problem, with the tags.



[ Reply to This | # ]