HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- altering file name
Operating System - Linux
        1839919
        Members
    
    
        3884
        Online
    
    
        110157
        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
10-29-2005 04:58 PM
10-29-2005 04:58 PM
			
				
					
					
						Hello,
I have a number of files that I need to alter the file name. The current file names are similar to this:
XYZ8976
XYZ7654
XYZ8765
What I want to do is put a underscore (_) after the charater 'Z' so I would want the files names to look like this:
XYZ_8976
XYZ_7654
XYZ_8765
How could I do this in UNIX?
Thanks,
Shaf
	
			
				
		
			
			
			
			
			
			
		
		
		
	
	
	
I have a number of files that I need to alter the file name. The current file names are similar to this:
XYZ8976
XYZ7654
XYZ8765
What I want to do is put a underscore (_) after the charater 'Z' so I would want the files names to look like this:
XYZ_8976
XYZ_7654
XYZ_8765
How could I do this in UNIX?
Thanks,
Shaf
Solved! Go to Solution.
		2 REPLIES 2
	
	            
            
		
		
			
            
                - Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2005 08:52 PM
10-29-2005 08:52 PM
Solution
			
				
					
					
						if all the files are in the same folder and begin with XYZ the following perl script will do the work,copy it to a file and execute "perl filename".Define the actual folder with XYZ files instead $folder:
chdir $folder;
foreach my $file (glob "XYZ*") {
my $newfile = $file;
$newfile =~ s/^XYZ/XYZ_/;
if (-e $newfile)
{
warn "can't rename $file to $newfile: $newfile exists\n";
}
else
{
rename $file, $newfile)
}
}
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
chdir $folder;
foreach my $file (glob "XYZ*") {
my $newfile = $file;
$newfile =~ s/^XYZ/XYZ_/;
if (-e $newfile)
{
warn "can't rename $file to $newfile: $newfile exists\n";
}
else
{
rename $file, $newfile)
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2005 03:06 AM
10-30-2005 03:06 AM
			
				
					
						
							Re: altering file name
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Solution was provided.
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
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
