Linux-Noob Forums
How to move .txt file so avi and txt has the same names - Printable Version

+- Linux-Noob Forums (https://www.linux-noob.com/forums)
+-- Forum: Linux Noob (https://www.linux-noob.com/forums/forum-3.html)
+--- Forum: Tips and Tricks (https://www.linux-noob.com/forums/forum-59.html)
+---- Forum: Filesystem Management (https://www.linux-noob.com/forums/forum-26.html)
+---- Thread: How to move .txt file so avi and txt has the same names (/thread-1272.html)



How to move .txt file so avi and txt has the same names - jerzykiller - 2007-07-05


1. I would like to say hello to everyone, because it is my first post :)

2. Some people are watching a lot of movies with subtitles. On example me :P Sometimes downloaded from some sites .txt file doesn't have the same name like ours .avi file. It's tiring to change these names in any gui application or even in console(usually there is a lot of other files like .rar, .r01...etc with similiar names). So I wrote this very little bash script which does that.



Code:
#!/bin/bash
mv *.txt $(basename *.avi .avi).txt




It will work only if in present dir is only one .txt and .avi file, and if these files names doesn't insist any spaces. I didn't know how to make it working with spaces. If anyone know, please let me know.

I hope it may be usefull for someone :]




How to move .txt file so avi and txt has the same names - znx - 2007-07-05


A slight modification, to allow you to specify the file and you can actually use a pure bash method (rather than with basename) and do:



Code:
#!/bin/bash
if [ $# -ne 2 ]; then
echo "usage: $0 <file.txt> <file.avi>" >&2
exit 1
fi
mv "$1" "${2%avi}txt"




Using *.avi, might lead to issues if you have multiple avi files in the one directory. Also note the quotes, to ensure spaces are still fine!

 

Sexy first post none the less ;)




How to move .txt file so avi and txt has the same names - jerzykiller - 2007-07-06


Thanks for help with this script. I actually always have one .txt and one .avi file (example below), and it is hard to type full name of txt file and avi file, because there are a lot of *.r?? files with similiar names. But that's in my case :]



Code:
orenji-the.4400.403.r00
orenji-the.4400.403.r01
orenji-the.4400.403.r02
orenji-the.4400.403.r03
orenji-the.4400.403.r04
orenji-the.4400.403.r05
orenji-the.4400.403.r06
orenji-the.4400.403.r07
orenji-the.4400.403.r08
orenji-the.4400.403.r09
orenji-the.4400.403.r10
orenji-the.4400.403.r11
orenji-the.4400.403.r12
orenji-the.4400.403.r13
orenji-the.4400.403.r14
orenji-the.4400.403.r15
orenji-the.4400.403.r16
orenji-the.4400.403.r17
orenji-the.4400.403.rar
orenji-the.4400.403.sfv
Sample
the.4400.pl.4x03.txt
the.4400.s04e03.dsr.xvid-orenji.avi
the.4400.s04e03.dsr.xvid-orenji.nfo




I'd use a lot of TAB's and I'd have to look really close for every dots, numbers and other things in the names ;P

I'm going to try to improve my script witch quotes. It didn't work for me before :P But maybe this time I do this right.

Thanks again :]