How to rename last part of file ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to rename last part of file ?
# 1  
Old 07-28-2016
How to rename last part of file ?

Hi,
I have large number of files like below -
Code:
UNIX FY17 D21-1c Active user audit - NPP dir owner listing(vctmstt01)_072816 - Notepad.pdf
UNIX FY17 D21-1c Active user audit - TTMS dir owner listing(pvcdmot35)_072816 - Notepad.pdf
UNIX FY17 D21-1c Active user audit - PCP dir owner listing(jumptitre01)_072816 - Notepad.pdf
UNIX FY17 D21-1c Active user audit - TTMS dir owner listing(squidpp40)_072816 - Notepad.pdf
UNIX FY17 D21-1c Active user audit - DRM dir owner listing(jumptitre02)_072816 - Notepad.pdf

I want to remove " - Notepad" and should look like below -
Code:
UNIX FY17 D21-1c Active user audit - NPP dir owner listing(vctmstt01)_072816.pdf
UNIX FY17 D21-1c Active user audit - TTMS dir owner listing(pvcdmot35)_072816.pdf
UNIX FY17 D21-1c Active user audit - PCP dir owner listing(jumptitre01)_072816.pdf
UNIX FY17 D21-1c Active user audit - TTMS dir owner listing(squidpp40)_072816.pdf
UNIX FY17 D21-1c Active user audit - DRM dir owner listing(jumptitre02)_072816.pdf

There are spaces as well in file name, so I am not able to figure out, how do I change it. Since there are 400+ files, it is difficult for me to copy on windows machine and rename every file.
Please suggest.
# 2  
Old 07-28-2016
Would the proposals in this thread help?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-28-2016
Code:
for i in *" - Notepad.pdf" ; do mv "$i" "${i% - Notepad.pdf}.pdf" ; done

This User Gave Thanks to rdrtx1 For This Post:
# 4  
Old 07-28-2016
Thanks. It worked
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

Find and rename part of a file

hi, Need your help. I need to write a script for below.. i have two files in directory /home/abc as below: Watch_20140203_abc.dat Watchnow_20140203_abc.dat I have to copy this file from /home/abc to /home01/home02 after that i have to rename the date part in above two files... (1 Reply)
Discussion started by: Vivekit82
1 Replies

4. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Rename file name / remove part of name

I have a whole file structure with jpeg files where I want to remove a part of the file name. An application added in many files a case conflict in the naming "xyz 017.jpg (Case Conflict 1)" So, can someone help me how to get rid of the " (Case Conflict 1)"? What I have is this: find . -name... (2 Replies)
Discussion started by: borobudur
2 Replies

6. Shell Programming and Scripting

rename file by removing some part of the file name

I am special requirements to rename file. I have files with names like below: 1_firstname1_lastname1.html 2_firstname2_lastname2.html 3_fistname3_lastname2.html I would like these file to be renamed as below firstname1_lastname1.html firstname2_lastname2.html... (5 Replies)
Discussion started by: McLan
5 Replies

7. Shell Programming and Scripting

Multiple rename part of scripts

i have about 30 scripts for example: test, test1,test2, test3, test4,..... inside every scripte is code like this: echo "input check OK" how to rename this line in multiple scripts in this: echo "input error!" (2 Replies)
Discussion started by: waso
2 Replies

8. UNIX for Dummies Questions & Answers

Help with multiple file rename - change case of part of file name

Hi there, I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is... (7 Replies)
Discussion started by: steve7
7 Replies

9. Shell Programming and Scripting

Rename part of multiple files

Hello, I have about 200 files named like script1234_test.sh script3434_test.sh and so on... I am trying to write a script that will rename those files from test to dev, keeping the rest of the file name intact. Could anyone help? Thanks. (4 Replies)
Discussion started by: sajjad02
4 Replies
Login or Register to Ask a Question