LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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


Reply
  Search this Thread
Old 09-05-2012, 09:38 AM   #1
joellpr
LQ Newbie
 
Registered: Sep 2012
Posts: 1

Rep: Reputation: Disabled
Question about perl script to rename multiple files


Hi

I have several files for instance:

abc_invoice_09052012.txt
abc_purchase_09052012.txt
abc_inventory_09052012.txt

the numbers on the name are the current date and it can change every day.

I need to rename without the _DATE, for instance:

abc_invoice.txt
abc_purchase.txt
abc_inventory.txt

but, also the number of files can change every day, could be between 8 to 12.

I'm kindly new on perl, and I have a perl script, it creates a zip file with these files and sent via sftp using expect.

I just need a routine or code to rename those files and include on my perl script running on Linux RHEL.

Thanks in advance!!
 
Old 09-05-2012, 01:36 PM   #2
cortman
Member
 
Registered: Jan 2012
Location: ZZ9 Plural Z Alpha
Distribution: Crunchbang 11, LFS 7.3, DSL 4.1.10, Lubuntu 12.10, Debian 7
Posts: 219

Rep: Reputation: 43
This should do the job.

Code:
#! /usr/bin/perl


while(<*>) {
	$oldname = $_;
	s/_[^_][0-9]*(?=\.)//;
	rename $oldname, $_
}

Last edited by cortman; 09-05-2012 at 01:37 PM.
 
1 members found this post helpful.
  


Reply



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
[SOLVED] rename files in folders using perl script pablgonz Programming 15 12-18-2011 12:22 PM
Help with bash script to rename multiple files zookman Programming 1 05-09-2011 03:23 AM
Another script to rename multiple files Becklan Programming 9 08-10-2010 09:18 AM
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 03:50 AM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-22-2008 11:25 PM

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

All times are GMT -5. The time now is 02:46 PM.

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
Open Source Consulting | Domain Registration