I have downloaded a series of files from https://www.grc.com/securitynow.htm which is a podcast. I downloaded 2 files per podcast.
File 1 is named sn-471.mp3 (I have 471 of these named sequentially) File 2 is named sn-471.txt (I have 471 of these named sequentially)
What I am trying to do is this, I am printing the 6th line of the file, and cutting from the 2nd delimiter to the end of line with this:
sed -n 6p sn-471.txt | cut -f2-
That is working perfectly right now. The reason for the 6th line is so far in my test, the 6th line is always the TITLE: and then a tab then the title of the episode. I assume that if i run into the issue where the 6th line is not always the title, then I can grep for TITLE: then use the same cut.
With the above I am able to print the Title of the episode. What I'm trying to do and cant seem to wrap my head around is use this data to then rename the mp3 file.
So far I have come up with this, but its not working.
#/bin/bash
for i in
sn-471.txt;
do
X=$(sed -n 6p $i | cut -f2-)
mv $i `${X}`.txt
done
I understand that i will need to make the "sn-471.txt" part something like "sn-*.txt" soon, but for this test this is what I have been using. If this has been covered already, I haven't been able to find it so far via various Google searches.
Thank all of you for any help you provide!
You can store the ouput of the sed
command to a variable with command substitution. You can then use parameter expansion to remove the ".txt" extension:
for file in sn-*.txt ; do
title=$( sed -n 6p "$file" | cut -f2- )
mv "${file%txt}"mp3 "$title".mp3
done