Question

I have a file that contains filenames like this:

my_cool_file.xxx
my_cool_file2.xxx
my_cool_file3.xxx

I have a folder that has:

some_file.xxx
some_file2.xxx
some_file3.xxx

I would like to have a bash script to take one line from the filename file and rename one file in the folder.

Is there a way to do this?

Was it helpful?

Solution

Note: This answer isn't that good generally, but it solved the OP's problem.

Do all files end with _file.xxx or _fileN.xxx?

Basically, is what you want to change just the prefix of the filenames?

Assuming I understand your problem correctly, and that the file without a number is last in file_list.txt the following should do the trick


COUNTER=0
for FILE in `ls *.xxx | sort`; do
    COUNTER=$(($COUNTER+1))
    echo Moving $FILE to `sed -n ${COUNTER}p file_list.txt`
    #mv "${FILE}" `sed -n ${COUNTER}p file_list.txt`
done

Comment in the line with mv if you want the actual move to happen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top