I would do this in multiple steps, since you do this rarely. Transparency is more important than automation here. But a single line is also possible. I assume that if you use only one command for all the files each step, this is what you intended.
You need to have ffmpeg
(or avconv
), shntool
and cuetools
installed.
To convert all your .ape
to .flac
in place:
find . -name "*.ape" -exec sh -c 'exec ffmpeg -i "$1" "${1%.ape}.flac"' _ {} \;
If you install the patched MAC encoder and decoder for APE files from http://www.etree.org/shnutils/shntool/, this first step is unnecessary. But you would need to compile it with g++
and yasm
yourself. Same goes for .tta
files, which are also often used instead of .ape
.
Split and name .flac
files:
find . -name "*.cue" -exec sh -c 'exec shnsplit -f "$1" -o flac -t "%n_%p-%t" "${1%.cue}.flac"' _ {} \;
If shnsplit
is also used for the conversion, replace the .flac
in "${1%.cue}.flac"
with the extension of the format you are converting from.
%n
– track number
%p
– performer
%t
– track name
is taken from the .cue
file for the .flac
file names. To tag the resulting, split .flac
files:
find . -name "*.cue" -execdir sh -c 'exec cuetag "$1" *.flac' _ {} \;
Remove the remaining CDImage.ape.cue
, CDImage.flac
, and CDImage.ape
files at your leisure. The names are unique, so a simple find . -name "CDImage*" -delete
is sufficient, except if Mozart made a composition starting with CDImage
which I am not aware of.
For shnsplit
to work, all necessary encoders/decoders need to be installed so it can read and write files. Modules for APE (and for the TTA format) would need to be compiled from source, the others by installing the package (i. e. FLAC).
This works for all standard cases where .cue
and .tta
/.flac
/.ape
files have the same name, except for the extension.
Side remark for others: If you deal with this conversion, your source files might be of Japanese origin, where APE and TTA were more popular than elsewhere. If the .cue
files were initially SHIFT-JIS coded and now opened as UTF-8, the shnsplit
step will break. You need to rename the .cue
files with
find . -name "*.cue" -exec rename 's/\.cue$/.cux/' -- {} +
and convert the intermediate files to UTF-8 with
find . -name "*.cux" -exec sh -c 'exec iconv -f SHIFT-JIS -t UTF-8 -o "${1%.cux}.cue" -- "$1"' _ {} \;
before you attempt to do the steps above. Don't forget to get rid of the .cux
files when you are done with:
find . -name "*.cux" -delete
Best Answer
In order to be sure no line break you can use other option than
c
.split a file by #number chunks so you can thus be sure they are equal and more no break in lines.Example
This will split the file.txt into 4 chunks.
OR you can split by number of lines
example
This will split the file.txt into files each is 200 lines. But this is not accurate that all are of same length since the last file maybe less than that number chosen.
Now with respect to the naming. The default of the command split is to use a default suffix "x" and default prefixes "aa" "ab" "ac" ...
So in order to change those default you have to state a suffix to use.
in your case you can use
The output would be like
file1_1.aa file1_1.ab file1_1.ac
Else you can change the default prefix to be numberic using
-d
The output would be like
file1_1.00 file1_1.01 file1_1.02
So you can't get the naming you want with default split unless you use some
awk
orsed
with REGEX.Now to read the set of files from a file lets called
files.list
UPDATE: I came to this https://unix.stackexchange.com/questions/32626/split-a-file-by-line-and-have-control-over-resulting-files-extension
According to second answer
So in your case if your split version is >8.16 then you can do your need like this
So output would be like