Rename 100+ files from a text file
Hello,
I have a folder with 114 files, these files are numbered 001, 002,... I want to rename these files to names found in a text file How can I do that?! Thanks. |
What's the format of the text file - how about some example lines?
|
i just did something similar
I have no idea if this works lol...
#!/bin/bash comm oldname newname > both for f in both; do first=`cat both | 'awk {print$1}'` second=`cat both | 'awk {print$2}'` mv $second $first done |
Thank you for your replies,
The files extention is mp3 and the text file format is txt I would like to change the files as follow: 001.mp3 ---> Wonders.mp3 002.mp3 ---> Magic.mp3 003.mp3 ---> lame.mp3 now the names; "wonders","magic","lame" are found in a text file how can I rename the long list of files? |
Sample lines?
|
The file will look like this:
Wonders Magic Lame I hope it helps. |
I'm sure you could do it more elegantly wit hawhk or some thing, btu try creating a script file like
Code:
#!/bin/sh -x |
This could be far better. At the moment, I'm assuming that the number of files is the same as the number of names and also that the order of items in your text file correctly matches the order of mp3 files. Both are bad assumptions. But this may give some ideas for you or others to improve:
Code:
#!/usr/bin/perl |
if you have Python
Code:
#!/usr/bin/env python |
use bash
#!/bin/bash
[ $# -lt 2 ] && { echo "Usage: script mp3dir namelist"; exit; } for f in $1/*; do ((n++)) name=$(sed -n "${n}p" $2) mv $f ${f/[0-9]*./${name}.} done |
All times are GMT -5. The time now is 11:00 PM. |