Jump to content
Sign in to follow this  
jerzykiller

How to move .txt file so avi and txt has the same names

Recommended Posts

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.

#!/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 :]

Share this post


Link to post
Share on other sites

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:

#!/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 ;)

Share this post


Link to post
Share on other sites

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 :]

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 :]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...