0

I have a lot of file with the same format (???_ideal.sdf) name and I need to rename all (???.sdf) removing form the name "ideal". For example:

Files: 
002_ideal.sdf 
ERT_ideal.sdf 
234_ideal.sdf 
sCX_idel.sdf

New Files:
002.sdf 
ERT.sdf 
234.sdf 
SCX.sdf

I thought to using a loop but I don’t know how to indicate that in the new file name should be removed "individual".

For example:

for file in ???_individual.sdf; mv $file what?

1

2 Answers 2

3

With your shown samples, could you please try following. This will only print the rename command on terminal(for safer side, check and make sure if commands are fine and looking ok to you first before actually renaming files), to perform actual rename remove echo from following.

for file in *_ideal.sdf
do
   echo mv "$file" "${file/_ideal/}"
done 
Sign up to request clarification or add additional context in comments.

Comments

0

Based on this answer you can also write it as one line with:

rename 's/^(.*)_ideal.png/$1.png/s' **/**

First parameter replaces the the _ideal.png, second one means all files.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.