[Solved] Rename file name / remove part of name


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Rename file name / remove part of name
# 1  
Old 04-23-2012
[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:

Code:
find . -name "*.jpg (Case Conflict 1)" -depth -exec rename '????' {} \;

Thanks!
# 2  
Old 04-23-2012
Hi borobudur,

One way:
Code:
$ perl -e 'for ( @ARGV ) { ($newfile = $_) =~ s/\(.*\)\Z// ; rename $_, $newfile and printf qq[%s\n], qq[Renamed $_] }' *jpg*
Renamed xyz 017.jpg (Case Conflict 1)
Renamed xyz 018.jpg (Case Conflict 1)

# 3  
Old 04-24-2012
Quote:
Originally Posted by birei
Hi borobudur,

One way:
Code:
$ perl -e 'for ( @ARGV ) { ($newfile = $_) =~ s/\(.*\)\Z// ; rename $_, $newfile and printf qq[%s\n], qq[Renamed $_] }' *jpg*
Renamed xyz 017.jpg (Case Conflict 1)
Renamed xyz 018.jpg (Case Conflict 1)

Thanks! But there is still a withe space at the end from ...jpg (C...
And an other thing is how can I walk recursively through the file structure?


---------- Post updated 04-24-12 at 01:00 PM ---------- Previous update was 04-23-12 at 08:27 PM ----------

That worked fine:
Code:
find . -type f -exec rename 's/\ \(Case Conflict 1\)$//' {} \;

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to rename last part of file ?

Hi, I have large number of files like below - 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... (3 Replies)
Discussion started by: solaris_1977
3 Replies

2. Shell Programming and Scripting

Remove or rename based on contents of file

I am trying to use the two files shown below to either remove or rename contents in one of those files. If in file1.txt $5 matches $5 of file2.txt and the value in $1 of file1.txt is not "No Match" then that value is substituted for all values in $5 and $1 of file2.txt. If however in $1 ... (5 Replies)
Discussion started by: cmccabe
5 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. Shell Programming and Scripting

Remove all digits and rename a file

Hi, I have a file nexus-1234 in a directory. I want to generate a random number and replace the 1234 with it and rename the file. So nexus-1234 becomes nexus-2863 after running the script. Any help is appreciated. Thanks in advance. (2 Replies)
Discussion started by: scorpioraghu
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

Remove part of the file

I have an xml file, from where I need to take out Application2 entries and keep the others. I need to remove from <product> to </product> and the key element to look for while removing should be <application> as other pairs can be same for others. <product> ... (10 Replies)
Discussion started by: chiru_h
10 Replies

8. Shell Programming and Scripting

remove certain part of file name

Hi, Is it possible to remove the first part of the file name using find. i.e i have something like 2006abc.txt , 1007bed.txt etc, I wanna rename them to abc.txt , bed.txt I tried some stupid way.. find . -name '*.txt' -exec mv {} `cut -f2-5 -d"_" {}` \; somehow iam not getting it. ... (3 Replies)
Discussion started by: braindrain
3 Replies

9. 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
Login or Register to Ask a Question