Rename not executing in centos 7 as expected

Login or Register to Reply

Thread Tools Search this Thread
# 1  
Rename not executing in centos 7 as expected

In the rename below the /path/to/folder... is trimmed (an example is in the parenthesis. Each .bam and .bam.bai in that trimmed directory in the bam sub-folder is then renamed by removing the IonCode_0000_ in the beginning of each filename, leaving just the unique id. The files are always in pairs that is there will always be a matching .bam and .bam.bai. The code executes correctly in ubuntu 14.04 but not in centos 7 as the files do not get renamed to the desired. I am not sure what is different as the rename utility is there in centos 7. The command does execute but the rename does not happen and the file is unchaged. Thank you Smilie.


IonCode_0000_16-1111-Last,First.bam             IonCode_0001_17-0000-L,F-REPEAT.bam
IonCode_0000_16-1111-Last,First.bam.bai         IonCode_0001_17-0000-L,F-REPEAT.bam.bai

mv "$RDIR" "${TRIMSTR}"  ## trim folder name to (/path/to/folder/R_2019_xx_xx_xx_xx_xx_yyyy_X1-0000-101) --- this is "$TRIMSTR" ---
     rename s/"IonCode_[0-9][0-9][0-9][0-9]_"/""/g "$TRIMSTR"/bam/*.bam
     rename s/"IonCode_[0-9][0-9][0-9][0-9]_"/""/g "$TRIMSTR"/bam/*.bam.bai


16-1111-Last,First.bam             17-0000-L,F-REPEAT.bam
16-1111-Last,First.bam.bai         17-0000-L,F-REPEAT.bam.bai

looks like centos has util-linux rename which doesn't support s/.../.../ but I am not sure how to adjust the rename in the script. Thank you Smilie.

rename -V
rename from util-linux 2.23.2

Last edited by cmccabe; 2 Weeks Ago at 09:34 AM.. Reason: added details
# 2  
First of all
rename s/"IonCode_[0-9][0-9][0-9][0-9]_"/""/g ...

works but looks misleading.
I would put the whole argument in quotes
rename "s/IonCode_[0-9][0-9][0-9][0-9]_//g" ...

Now to your question. The rename command is not portable. There are at least two different implementations in Linux distros.
Consult/compare the man pages!
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Script is not executing as expected when I schedule it in cron
Nagaraj R
Hi, I have a shell script which fetches the MRP status and the LAG status. When I execute it manually like, sh <script_name>, it fetches the output as expected, but when I schedule through crontab, it's not working as expected. Any help would be really appreciated. Here is the code...... AIX
Binary Operator expected while executing the below shell script.
Jagadish m
Hi Experts, Iam bit poor in shell scripting, Here my requirement is for generating an alert where the oracle database db_recovery_file_dest_size usage. If it reaches beyond 80% should recieve an alert through an email. Want to schedule this alert in cron. #!/bin/bash ....... Shell Programming and Scripting
Shell Programming and Scripting
How to Upgrade Centos 5.7 using Centos 5.8 ISO image on Vmware workstation
Dear Linux Experts, On my windows 7 desktop with the help of Vmware workstation (Version 7.1), created virtual machine and installed Centos 5.7 successfully using ISO image. Query : Is this possible to upgrade the Centos 5.7 using Centos 5.8 ISO image to Centos version 5.8?.. if yes kindly...... Red Hat
Red Hat
executing script by cron doesnt give me expected result
Hi frnds... I m facing very irritating problem already waisted my 2 days.. I have a following script..( i am pasting only the main code) ftp -ivn <<FTP user $user $password binary cd $FileDir/out lcd $localpath get $file rename $FileDir/out/$file $FileDir/tmp/$file...... UNIX for Advanced & Expert Users
UNIX for Advanced & Expert Users