Sample Header Ad - 728x90

Scripting id3 tags with id3v2 and sed

3 votes
1 answer
6642 views
I am trying to write a script to automatically add track and title info to an mp3 file's id3 tag. At this point, I have sed grabbing the info from the filename and formatting it to fit the id3v2 command, but upon hitting a multi-word title, I get the error Couldn't stat file ''. If I just echo the id3v2 command that is being run, I see the command in this format: id3v2 -t Title\ Of\ Track -T 1 1_-_Title_Of_Track.mp3 Copy/pasting that text into the terminal executes tagging properly, but of course lacks the intended automation of scripting. So here's what the script intending to automate the process looks like: #!/bin/bash for track in *.mp3 ; do id3v2 $(echo ${track} | sed -e 's/^\([1-9][0-9]*\)_-_\(.*\).mp3/-t \2 -T \1/' -e 's/_/\\ /g') ${track} done Any insight as to why the title is treated as a single argument when manually typed but not when scripted?
Asked by Christian Gibbons (344 rep)
Aug 21, 2018, 02:14 PM
Last activity: Aug 22, 2018, 03:25 AM