Renaming files to remove everything before one parenthesis


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Renaming files to remove everything before one parenthesis
# 1  
Old 02-08-2015
Renaming files to remove everything before one parenthesis

Hi,

I have files in a folder that I would like all renamed without the preceding number and parenthesis. For example, I have files of the name

Code:
08) Great Good Fine Ok - Not Going Home
09) Roosevelt - Small Hours
10) RAC - I Should've Guessed Feat. SPEAK

and I would like them all to be renamed

Code:
 Great Good Fine Ok - Not Going Home
 Roosevelt - Small Hours
 RAC - I Should've Guessed Feat. SPEAK

What would be the correct way to go about this?
# 2  
Old 02-08-2015
Try:
Code:
for i in *\)\ * 
do
  mv -- "$i" "${i#*) }"
done

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 02-08-2015
Thank you!

I have a follow-up question, however. How should I modify the above if I have files with spaces and dashes instead? For instance,

Code:
008 - Great Good Fine Ok - Not Going Home
009 - Roosevelt - Small Hours
010 - RAC - I Should've Guessed Feat. SPEAK

and I would like them all to be renamed

Code:
 Great Good Fine Ok - Not Going Home
 Roosevelt - Small Hours
 RAC - I Should've Guessed Feat. SPEAK

# 4  
Old 02-08-2015
Hello jyu429,

Could you please try following and let me know if this helps.
Code:
for i in *\-* 
do  
echo "mv --" "$i"  "${i#*\- }" 
done

If happy with results of above command please try following then.

Code:
for i in *\-*
do  
    mv -- "$i" "${i#*\- }" 
done

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 02-08-2015
Quote:
Originally Posted by jyu429
How should I modify the above if I have files with spaces and dashes instead?
What Scrutinizer showed you is called "parameter expansion" in the shell. You might want to look that up in the man page of your shell and learn how it works.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming Files

I have a directory with a long list of files. I want to change their names such that the first letter of the name of the author is capitalised. I have tried the following command and did not get what I require. rename 'y/....../....../' *.pdf 2007--nystrom--Diss.pdf... (1 Reply)
Discussion started by: Danette
1 Replies

2. Shell Programming and Scripting

Remove parenthesis and run awk calculation

The awk below works fine if I manually remove the () from file1. However, when I try to use tr to remove the () and then | into awk to run the calculation no result is obtained. Is there a way to tell the awk to ignore the () in fiile1 if they are there or do I need to remove them first? Thank... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

4. Shell Programming and Scripting

renaming files

Hi, I have a list of files in a folder with the same name ending (over 1000 files) joe.jpy.jpeg joe1.jpy.jpeg joe2.jpy.jpeg jon3.jpy.jpeg jor5.jpy.jpeg .....jpy.jpeg etc. I want to change jpy to hhk So the output will be: joe.hhk.jpeg joe1.hhk.jpeg joe2.hhk.jpeg jon3.hhk.jpeg... (3 Replies)
Discussion started by: kylle345
3 Replies

5. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

6. UNIX for Advanced & Expert Users

Renaming files

Hello Please can someone help. We are being sent a directiory full of images. The names of these images can vary in length and have spaces in them. example: nn 999999 nnnnn nnnn nnnn nn nnn nnn nn nnnn.pdf what we want to do is rename all the images. Take the first two fields nn 999999 and... (23 Replies)
Discussion started by: Dolph
23 Replies

7. UNIX for Advanced & Expert Users

renaming files

How can I rename files with .c to .cpp in my current directory and if any directory present in current directory system should descend in to that and checks ( find ).... tell me how to achieve this using find command and other if any? thanks. (7 Replies)
Discussion started by: shahnazurs
7 Replies

8. Shell Programming and Scripting

Remove parenthesis character (Perl)

Hello, i'm unable to remove the parenthesis character. With $parsed_AsciiName =~ s/\(//; the string is the same And with $parsed_AsciiName =~ s/(//; i retrieve "Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE" Any ideas, please? thank you in advanced. (4 Replies)
Discussion started by: aristegui
4 Replies

9. UNIX for Dummies Questions & Answers

Need help renaming files

I just can't figure this one out. I have a lot of files name (for example) ABC1234.5678.ext I need to rename these files U0105678PQRS So I'm removing everything before the first "." I'm keeping "5678" in the file name Adding "U010" to the front of "5678" Dropping the ".ext" extension ... (5 Replies)
Discussion started by: bbbngowc
5 Replies

10. Shell Programming and Scripting

Need to only remove parenthesis and : leave the rest

Hi all, I'm stuck on this last part...am running a simple script under AIX to extract NetView host IP addresses. The line below returns the IP address in parenthesis with a trailing colon, i.e. ping -c 1 $name |grep \( | awk '{ print $3 }' --------> returns (a.b.c.d): How can I only... (10 Replies)
Discussion started by: livinthedream
10 Replies
Login or Register to Ask a Question