string - How do I insert the results of several commands on a file as part of my sed stream? -
i use djing software on linux (xwax) uses 'scanning' script (visible here) compiles music files available software , outputs string contains path filename , title of mp3. example, if scans path-to-mp3/artist - test.mp3, spit out string so:
path-to-mp3/artist - test.mp3[tab]artist - test
i have tagged mp3s bpm information via id3v2 tool , have commandline method extracting information follows:
id3v2 -l name-of-mp3.mp3 | grep tbpm | cut -d: -f2
that spits out numerical bpm me. i'd prepend bpm number above command part of xwax scanning script, i'm not sure how insert command in midst of script. i'd want generate is:
path-to-mp3/artist - test.mp3[tab][bpm]artist - test
any ideas?
it's not clear me where in script want insert bpm number, idea this:
to embed output of 1 command arguments of another, can use "command substitution" notation
`...`
or$(...)
. example, this:rm $(echo abcd)
runs command
echo abcd
, substitutes output (abcd
) overall command; that's equivalentrm abcd
. remove file namedabcd
.the above doesn't work inside single-quotes. if want, can put outside quotes, did in above example; it's safer put inside double-quotes (so prevent unwanted postprocessing). either of these:
rm "$(echo abcd)" rm "a$(echo bc)d"
will remove file named
abcd
.in case, need embed command substitution middle of argument that's single-quoted. can putting single-quoted strings , double-quoted strings right next each other no space in between, bash combine them single argument. (this works unquoted strings.) example, either of these:
rm a"$(echo bc)"d rm 'a'"$(echo bc)"'d'
will remove file named
abcd
.
edited add: o.k., think understand you're trying do. have command either (1) outputs out files in specified directory (and subdirectories , on), 1 per line, or (2) outputs contents of file, contents of file list of files, 1 per line. in either case, it's outputting list of files, 1 per line. , you're piping list command:
sed -n ' { # /[<num>[.]] <artist> - <title>.ext s:/\([0-9]\+.\? \+\)\?\([^/]*\) \+- \+\([^/]*\)\.[a-z0-9]*$:\0\t\2\t\3:pi t # /<artist> - <album>[/(disc|side) <name>]/[<abnum>[.]] <title>.ext s:/\([^/]*\) \+- \+\([^/]*\)\(/\(disc\|side\) [0-9a-z][^/]*\)\?/\([a-h]\?[a0-9]\?[0-9].\? \+\)\?\([^/]*\)\.[a-z0-9]*$:\0\t\1\t\6:pi t # /[<abnum>[.]] <name>.ext s:/\([a-h]\?[a0-9]\?[0-9].\? \+\)\?\([^/]*\)\.[a-z0-9]*$:\0\t\t\2:pi } '
which runs sed
script on list. want of replacement-strings change \0\t...
\0\tbpm\t...
, bpm
bpm number computed command. right? , need compute bpm number separately each file, instead of relying on sed
s implicit line-by-line looping, need handle looping yourself, , process 1 line @ time. right?
so, should change above command this:
while read -r line ; # loop on lines, saving each 1 "$line" bpm=$(id3v2 -l "$line" | grep tbpm | cut -d: -f2) # save bpm "$bpm" sed -n ' { # /[<num>[.]] <artist> - <title>.ext s:/\([0-9]\+.\? \+\)\?\([^/]*\) \+- \+\([^/]*\)\.[a-z0-9]*$:\0\t'"$bpm"'\t\2\t\3:pi t # /<artist> - <album>[/(disc|side) <name>]/[<abnum>[.]] <title>.ext s:/\([^/]*\) \+- \+\([^/]*\)\(/\(disc\|side\) [0-9a-z][^/]*\)\?/\([a-h]\?[a0-9]\?[0-9].\? \+\)\?\([^/]*\)\.[a-z0-9]*$:\0\t'"$bpm"'\t\1\t\6:pi t # /[<abnum>[.]] <name>.ext s:/\([a-h]\?[a0-9]\?[0-9].\? \+\)\?\([^/]*\)\.[a-z0-9]*$:\0\t'"$bpm"'\t\t\2:pi } ' <<<"$line" # take $line input, rather reading more lines done
(where change sed
script insert '"$bpm"'\t
in few places switch single-quoting double-quoting, insert bpm, switch single-quoting , add tab).
Comments
Post a Comment