removing a word in a multiple file starting at the dot extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing a word in a multiple file starting at the dot extension
# 1  
Old 08-23-2011
removing a word in a multiple file starting at the dot extension

hi

I would like to ask if someone knows a command or a script on how to rename a multiple file in the directory starting at the end of the filename or at the .extension( i would like to remove the last 11 character before the extension) for example

Below is the result of my command ls inside the directory

Quote:
BBC_In_footsteps_of_Alexander_the_mountain_20-v3veN2U__3I.mp4
BBC_In_the_footsteps_of_Alexander_Afghanistan_17-thAS28SWKKU.mp4
BBC_In_the_footsteps_of_Alexander_Alexandria_7-rQcjjpRwqw4.mp4
BBC_In_the_footsteps_of_Alexander_army_revolts_26-Jwrl2hPSFWA.mp4
BBC_In_the_footsteps_of_Alexander_Bactria_19-cC5pGsUgyiM.mp4
BBC_In_the_footsteps_of_Alexander_climbing_pir_sar_24-oz0pb-Zycvc.mp4
BBC_In_the_footsteps_of_Alexander_Darius_Dies_13-Pn9nj7rWT60.mp4
BBC_In_the_footsteps_of_Alexander_ending_31-4wW8nJi5tOk.mp4
BBC_In_the_footsteps_of_Alexander_ends_of_earth_22-uMgX_UDHo4g.mp4
BBC_In_the_footsteps_of_Alexander_Gaza_6-pr2mkAgQL9k.mp4
BBC_In_the_footsteps_of_Alexander_gordion_knot_4-5nfmZfEV_wA.mp4
BBC_In_the_footsteps_of_Alexander_Indus_Delta_29-8CiauNRLSUU.mp4
.....
Quote:
BBC_In_footsteps_of_Alexander_the_mountain_20.mp4
BBC_In_the_footsteps_of_Alexander_Afghanistan_17.mp4
The filename has no predefined length or has diff length so starting at the beggining of the filename is not much use.

Im using pyrenamer but the delete option will start counting character at the beggining of the filename and there has no option that will start deleting at the end of after the extension.

Thanks for any input..
# 2  
Old 08-23-2011
Code:
sed 's/.\{12\}\(\..*\)/\1/' Inp_File

# 3  
Old 08-23-2011
Assuming you have BASH or a recent KSH:

Code:
find ./ -iname 'BBC_*.mp4' | while IFS="." read NAME EXT
do
        echo mv "$NAME.$EXT" "${NAME:0:$((${#NAME}-11))}.$EXT"
done

Remove the 'echo' once you're sure it does what you want.
# 4  
Old 08-23-2011
Thanks very much for a helpful response

By the way i solve my problem by using this single command below

Quote:
#rename -n 's/^(.*)-.{11}\.mp4$/$1.mp4/' *.mp4
# 5  
Old 08-23-2011
You didn't say what system you had, so everyone worked under the assumption you didn't have that.
# 6  
Old 08-25-2011
@Corona688: Im sorry i didn't state what system im working with its ubuntu. Im sorry by the way i tried your script and i would like to ask about the NAME is it a variable that i need to assigned. Cause when i used it throws me this error

Quote:
line 5: $((${#NAME}-11)): substring expression < 0
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files based on specific word in a file name & its extension and putting it in required location

Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
Discussion started by: prajaktaraut
13 Replies

2. Shell Programming and Scripting

Rename except dot file extension

After reading the manual of the command rename I would like to apply it to a folder with a couple of files containing old style dots before the file-type, e.g. up.to.the.roof.avi. So I'd like to rename them without the dots in between. Therefore I tried it the following way rename -f -n ... (4 Replies)
Discussion started by: 1in10
4 Replies

3. UNIX for Dummies Questions & Answers

ls command with wild card can't return filenames starting with dot

I came across the following behaviour in Solaris 10 (x86-64bit) and RHEL 5.6 (Tikanga) -a option in ls command is supposed to list all files starting with a dot. From the man page of ls -a, --all do not ignore entries starting with . $ touch .mytestfile $ vi .mytestfile $... (2 Replies)
Discussion started by: kraljic
2 Replies

4. Shell Programming and Scripting

how to remove a variable starting with dot using sed command

Hi, I want to remove a variable starting with dot(.) in a file using sed command. aaa sss .abc s/^\.abc/d I tried this but it didnt worked. (5 Replies)
Discussion started by: vdhingra123
5 Replies

5. Shell Programming and Scripting

How to Removing a dot from a file name?

I need a script that will allow me to rename all of my files in subdir /FilesIn as follows: From kumc_835_111200.RMT.dat to kumc_835_111200RMT.dat kumc_835_111200.KMR.dat to kumc_835_111200KMR.dat .................etc How do I do that whithout doing a sed ... (10 Replies)
Discussion started by: mrn6430
10 Replies

6. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

7. Shell Programming and Scripting

How to put a word starting at particular position in a file using shell scripting

Hi all, I'm new to shell scripting and hence this query. I have 2 files. temp.txt and config.txt. The values in temp.txt are tab separated. ex: temp.txt AB CDE GHIJ OPQRS WXY ex:config.txt (1st line for 1st element of temp.txt and so on) start = '1' end='5' start = '6' end =... (26 Replies)
Discussion started by: subhrap.das
26 Replies

8. Shell Programming and Scripting

removing DOT by using perl

Hi Friends, I have a variable which has a number (e.g. 12.1234). I want to remove "." (dot) from that number i.e. 121234 I want to do this using perl. Can you please guide me Thank you Anushree (2 Replies)
Discussion started by: anushree.a
2 Replies

9. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

10. Solaris

removing particular lines ending with a .cnt extension in a text file

I have a text file with rows of information (it is basically a ls command information(o/p from ls command)) I need to remove the lines ending with a .cnt extension and keep the lines ending with .zip extension, how to accomplish this. I also only need the date,size and name of the file from every... (2 Replies)
Discussion started by: ramky79
2 Replies
Login or Register to Ask a Question