HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- renaming files
Operating System - HP-UX
1829820
Members
1964
Online
109993
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2008 09:18 AM
11-03-2008 09:18 AM
Hi,
I have a list of files as below:
tacr013444.bdt
tacr013444.bid
tacr014444.bdt
tacr014444.bid
tacr015444.bdt
tacr015444.bid
tacr016444.bdt
tacr016444.bid
I am trying to rename the 444 character to 344 as below
tacr013444.bdt ---> tacro13344.bdt
tacr013444.bid ---> tacro12344.bid
tacr014444.bdt ---> tacr014344.bdt
tacr014444.bid
tacr015444.bdt
tacr015444.bid
tacr016444.bdt
tacr016444.bid
Kindly assist with you inputs. Thanking you in advance
I have a list of files as below:
tacr013444.bdt
tacr013444.bid
tacr014444.bdt
tacr014444.bid
tacr015444.bdt
tacr015444.bid
tacr016444.bdt
tacr016444.bid
I am trying to rename the 444 character to 344 as below
tacr013444.bdt ---> tacro13344.bdt
tacr013444.bid ---> tacro12344.bid
tacr014444.bdt ---> tacr014344.bdt
tacr014444.bid
tacr015444.bdt
tacr015444.bid
tacr016444.bdt
tacr016444.bid
Kindly assist with you inputs. Thanking you in advance
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2008 10:27 AM
11-03-2008 10:27 AM
Solution
Hi:
You could do:
# cat ./myrename
#!/usr/bin/perl
use strict;
use warnings;
my $newname;
while (<>) {
chomp;
next unless -f $_;
if (m/^tacr\d+?444\..+/) {
( $newname = $_ ) =~ (s/(^tacr\d+?)444(\..+)/${1}344${2}/);
if ( -f $newname ) {
print +( "$newname already exists!\n" );
next;
}
rename( $_, $newname );
}
}
...run as:
# ./myrename file
...where 'file' contains your list of filenames.
This will not clobber existing files of the target name, but leave the old name intact.
Regards!
...JRF...
You could do:
# cat ./myrename
#!/usr/bin/perl
use strict;
use warnings;
my $newname;
while (<>) {
chomp;
next unless -f $_;
if (m/^tacr\d+?444\..+/) {
( $newname = $_ ) =~ (s/(^tacr\d+?)444(\..+)/${1}344${2}/);
if ( -f $newname ) {
print +( "$newname already exists!\n" );
next;
}
rename( $_, $newname );
}
}
...run as:
# ./myrename file
...where 'file' contains your list of filenames.
This will not clobber existing files of the target name, but leave the old name intact.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2008 10:30 AM
11-03-2008 10:30 AM
Re: renaming files
something along the lines of:
for a in `ls tacr*4444.*`
do
newname=`echo $a | sed 's/4444\./3444\./g'
echo $a $newname
# mv $a $newname
done
ought to get you started. beware of spaces in names, name collisions and such...as the above checks nothing and procedes blindly.
if it looks right when run, then uncomment the "mv" and run with it...
for a in `ls tacr*4444.*`
do
newname=`echo $a | sed 's/4444\./3444\./g'
echo $a $newname
# mv $a $newname
done
ought to get you started. beware of spaces in names, name collisions and such...as the above checks nothing and procedes blindly.
if it looks right when run, then uncomment the "mv" and run with it...
- Tags:
- mv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2008 10:57 AM
11-03-2008 10:57 AM
Re: renaming files
I use PERL for such excercises.
First I make a test to 'see' that it will do the right thing.
For example using 'ls' to find the target files:
ls tac*444.b* | perl -lne 'chomp; $o = $_; s/444\.b/344.b/; print "rename $o, $_" '
Or using the perl glob:
perl -le 'while () { $o = $_; s/444\.b/344.b/; print "rename $o, $_" }'
When satisfied, remove the print and make it real:
perl -le 'while () { $o = $_; s/444\.b/344.b/; rename $o, $_ }'
Babys teps:
-e '...' # command follows in quotes.
while () # loop over glob results, putting each output in automatic variable $_.
{ # block
$o = $_; # make copy of original file name
s/444\.b/344.b/; # substitute $_ data, with anchors as needed
rename $o, $_ # Real work, as function call
} # end-of-block for while.
hth,
Hein.
First I make a test to 'see' that it will do the right thing.
For example using 'ls' to find the target files:
ls tac*444.b* | perl -lne 'chomp; $o = $_; s/444\.b/344.b/; print "rename $o, $_" '
Or using the perl glob:
perl -le 'while (
When satisfied, remove the print and make it real:
perl -le 'while (
Babys teps:
-e '...' # command follows in quotes.
while (
{ # block
$o = $_; # make copy of original file name
s/444\.b/344.b/; # substitute $_ data, with anchors as needed
rename $o, $_ # Real work, as function call
} # end-of-block for while.
hth,
Hein.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP