I use DJing software on linux (xwax) which uses a ‘scanning’ script (visible here) that compiles all the music files available to the software and outputs a string which contains a path to the filename and then the title of the mp3. For example, if it scans path-to-mp3/Artist – Test.mp3, it will spit out a string like so:
path-to-mp3/Artist - Test.mp3[tab]Artist - Test
I have tagged all my mp3s with BPM information via the id3v2 tool and have a commandline method for extracting that information as follows:
id3v2 -l name-of-mp3.mp3 | grep TBPM | cut -D: -f2
That spits out JUST the numerical BPM to me. What I’d like to do is prepend the BPM number from the above command as part of the xwax scanning script, but I’m not sure how to insert that command in the midst of the script. What I’d want it to generate is:
path-to-mp3/Artist - Test.mp3[tab][bpm]Artist - Test
Any ideas?
It’s not clear to me where in that script you want to insert the BPM number, but the idea is this:
To embed the output of one command into the arguments of another, you can use the “command substitution” notation
`...`or$(...). For example, this:runs the command
echo abcdand substitutes its output (abcd) into the overall command; so that’s equivalent to justrm abcd. It will remove the file namedabcd.The above doesn’t work inside single-quotes. If you want, you can just put it outside quotes, as I did in the above example; but it’s generally safer to put it inside double-quotes (so as to prevent some unwanted postprocessing). Either of these:
will remove the file named
abcd.In your case, you need to embed the command substitution into the middle of an argument that’s mostly single-quoted. You can do that by simply putting the single-quoted strings and double-quoted strings right next to each other with no space in between, so that Bash will combine them into a single argument. (This also works with unquoted strings.) For example, either of these:
will remove the file named
abcd.Edited to add: O.K., I think I understand what you’re trying to do. You have a command that either (1) outputs out all the files in a specified directory (and any subdirectories and so on), one per line, or (2) outputs the contents of a file, where the contents of that file is a list of files, one per line. So in either case, it’s outputting a list of files, one per line. And you’re piping that list into this command:
which runs a
sedscript over that list. What you want is for all of the replacement-strings to change from\0\t...to\0\tBPM\t..., whereBPMis the BPM number computed from your command. Right? And you need to compute that BPM number separately for each file, so instead of relying onseds implicit line-by-line looping, you need to handle the looping yourself, and process one line at a time. Right?So, you should change the above command to this:
(where the only change to the
sedscript itself was to insert'"$BPM"'\tin a few places to switch from single-quoting to double-quoting, then insert the BPM, then switch back to single-quoting and add a tab).