LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-08-2007, 06:28 PM   #1
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Rep: Reputation: 30
Need help with a command


I have 800 files, that start with

cs_CounterTerrorist_sarnia_OBCube_fluidsurface_final_0000.bvel.gz
cs_CounterTerrorist_sarnia_OBCube_fluidsurface_final_0000.bobj.gz
cs_CounterTerrorist_sarnia_OBCube_fluidsurface_particles_0000.gz
cs_CounterTerrorist_sarnia_OBCube_fluidsurface_preview_0000.bobj.gz

and follow until

cs_CounterTerrorist_sarnia_OBCube_fluidsurface_final_0199.bvel.gz
cs_CounterTerrorist_sarnia_OBCube_fluidsurface_final_0199.bobj.gz
cs_CounterTerrorist_sarnia_OBCube_fluidsurface_particles_0199.gz
cs_CounterTerrorist_sarnia_OBCube_fluidsurface_preview_0199.bobj.gz

What I need to do is add the number 6430 to every number in all of those files.. so that the first four would begin at 6430 and the last four would end at 6629.

I know this can be done with a shell command, but I would have no idea of even how to start. Could somebody please give me an idea on how to do this?
 
Old 05-08-2007, 06:43 PM   #2
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
WARNING! Test this first with sample files. I'm just typing in what I'd start with. I have not tried it to verify I got it all accurate! Put the script in the same directory where your files exist, and run it from that directory.
Code:
#!/bin/perl
while (`ls`) {
  chomp;
  $oldfile = $_;
  if ($oldfile =~ /(.*)(\d{4})(.*)/) {
    $newnumber = $2 + 6430;
    $newfile = "$1$newnumber$3";
    print "MOVING $oldfile to $newfile\n";
#    `mv $oldfile $newfile`;
  }
}
You can see I commented-out the actual mv command. Run it that way for testing to make sure it does what you want (and that I didn't screw up my example!) This example assumes it can identify the files you want to rename because they contain exactly four digits one after the other in their filename. After testing, un-comment the mv command and go for it.

There's probably an easier way. I'm just so used to PERL, that I naturally grab that for problems like this. Just because I'm comfortable with it.
 
Old 05-10-2007, 02:31 PM   #3
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Original Poster
Rep: Reputation: 30
Hey there, thanks for your help. I'm having trouble getting perl to run.. I didnt have it installed, so I installed it via rpm, but my system crashes whenever I try to call /bin/perl . If you have any suggestions, let me know.. but if not I'm just going to try and translate what you gave me into a shell script.

Thanks again
 
  


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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 02:23 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 04:35 PM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
Command to display whole filestructure hierarchy f/ command line? mjewell Linux - Newbie 10 01-19-2004 10:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:57 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
Open Source Consulting | Domain Registration