Rename not executing in centos 7 as expected


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename not executing in centos 7 as expected
# 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.

/path/to/folder/R_2019_xx_xx_xx_xx_xx_yyyy_X1-0000-101-v0.6_xxx_xxxxx_xxxxx_xxxxx

Code:
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

Code:
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

desired
/path/to/folder/R_2019_xx_xx_xx_xx_xx_yyyy_X1-0000-101/bam

Code:
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.

Code:
rename -V
rename from util-linux 2.23.2


Last edited by cmccabe; 05-02-2019 at 10:34 AM.. Reason: added details
# 2  
First of all
Code:
rename s/"IonCode_[0-9][0-9][0-9][0-9]_"/""/g ...

works but looks misleading.
I would put the whole argument in quotes
Code:
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 for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #252
Difficulty: Easy
Network computer devices that originate, route and terminate the data are called server-only devices.
True or False?

6 More Discussions You Might Find Interesting

1. AIX

Script is not executing as expected when I schedule it in cron

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... (3 Replies)
Discussion started by: Nagaraj R
3 Replies

2. Shell Programming and Scripting

Binary Operator expected while executing the below shell script.

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 .... (9 Replies)
Discussion started by: Jagadish m
9 Replies

3. Red Hat

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... (2 Replies)
Discussion started by: Ananthcn
2 Replies

4. Shell Programming and Scripting

+: more tokens expected

Hey everyone, i needed some help with this one. We move into a new file system (which should be the same as the previous one, other than the name directory has changed) and the script worked fine in the old file system and not the new. I'm trying to add the results from one with another but i'm... (4 Replies)
Discussion started by: senormarquez
4 Replies

5. UNIX for Advanced & Expert Users

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 213.194.40.77 <<FTP user $user $password binary cd $FileDir/out lcd $localpath get $file rename $FileDir/out/$file $FileDir/tmp/$file... (1 Reply)
Discussion started by: clx
1 Replies

6. Shell Programming and Scripting

elif not expected

Hi, I have a shell script which runs fine when i do it from Unix simulator on Widnows. When i try to run the same for Unix it throws me the error syntax error at line 87: `elif' unexpected. Piece of code for the same is while do if ; then shift configFile="$1"... (9 Replies)
Discussion started by: pv0428
9 Replies

Featured Tech Videos