LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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


Closed Thread
  Search this Thread
Old 01-24-2004, 02:24 AM   #1
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Rep: Reputation: 15
Need a perl programer to help me out with a script...


Hi, I don't know how to do system calls or program all that well in perl so I came here for help.

I have files that I need to rename in large amounts. The problem is they all have numbers in front of them and I need to get rid of these numbers and keep the rest of the name intact. here are examples of my problem.

110 blah blah.file
01 blahbla.file
73 blah bladh.file

I just need to get rid of the numbers and the whitespace after them. I figured you could do this by deleting characters in the name string until you hit a letter with the ASCII decimal equivelants but i don't know how to do that in perl and make the system calls. If anyone can help I would be very appreciative.

thank you

PS they are all in one directory.
 
Old 01-24-2004, 08:50 AM   #2
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Rep: Reputation: 30
use a regular expression to strip the ws and digits...

if ( $filename ~= /^[0-9]+[ \t]+(.*)/ ) {
$newfilename = $1;
}

as for actually renaming, I can't remember the exact system call to use. lookup www.perldoc.com.

Last edited by ugenn; 01-24-2004 at 08:52 AM.
 
Old 01-24-2004, 12:00 PM   #3
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Original Poster
Rep: Reputation: 15
but will that take care of multipe digit numbers at the front of the file name?
 
Old 01-24-2004, 12:19 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
easy one liner....
Code:
for i in *; do mv $i `echo $i | sed s/^[0-9]*\ //`; done
but then that's just bash... what a divvy...

Last edited by acid_kewpie; 01-24-2004 at 12:27 PM.
 
Old 01-24-2004, 02:47 PM   #5
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php

Duplicate to post in Newbie:
http://www.linuxquestions.org/questi...hreadid=137930

I'd say this belongs in Programming more than Newbie, but since you got the answer to your question in the Newbie post I'll close this one.
 
  


Closed Thread



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
C++ code,please C++ programer to give me some advise naihe2010 Programming 13 10-17-2005 10:30 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM
Need to hire a programer! suse7.1user Programming 2 08-17-2003 02:24 PM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM

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

All times are GMT -5. The time now is 12:06 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