LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 10-12-2017, 05:15 PM   #1
biplabbijay
Member
 
Registered: Jul 2009
Posts: 89

Rep: Reputation: 15
Shell script to add leading zeros to the file name.


Hi,

I have several ps files with names like

115_378D-014R315.57753.ps.

15_362D-014R315.25765.ps

I want to rename the files with a leading zero, something like,

0115_378D-014R315.57753.ps.
15_362D-014R315.25765.ps


I used the following command

Quote:
rename 's/\d+/sprintf("%04d", $&)/e' *.ps
which worked well in ubuntu 16.10. But it does not work in Cent OS. Is there any way to do this ?

Please help me in this regard.

Biplab
 
Old 10-13-2017, 02:58 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,564

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
I would suggest researching which version / type of rename you are running in both places. The Ubuntu version is probably the perl script one so if you want CentOS to behave the same, simply install that version.

You could also write a simple for loop in bash and use mv.
 
Old 10-13-2017, 03:00 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,995

Rep: Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218
Duplicate post - answered in the other thread.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to retain leading zeros in excel when sending through mail harekrushna Linux - Newbie 4 11-30-2015 05:17 PM
[SOLVED] How to remove leading zeros in a function santosh0782 Linux - Newbie 5 03-05-2014 04:53 AM
BASH: Keeping/replacing leading zeros with BC Checksumfail Programming 3 07-20-2012 04:29 PM
How to add leading zeros to numbers for file names rootaccess Linux - General 20 06-16-2012 08:35 PM
Renaming files (adding leading zeros) General Linux - Software 3 01-09-2011 10:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration