The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing ^D and ^H characters arsheshadri HP-UX 1 06-26-2008 09:01 AM
Special meaning characters in dir names JWilliams UNIX for Dummies Questions & Answers 2 03-07-2008 07:39 AM
Weird Ascii characters in file names yamsin789 Shell Programming and Scripting 2 10-07-2007 11:27 AM
Help with removing characters like ^M chiru_h Shell Programming and Scripting 16 02-13-2007 10:07 AM
Replace characters in all file names in a particular directory madhunk Shell Programming and Scripting 4 02-16-2006 07:10 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-17-2009
euspilapteryx euspilapteryx is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 7
Unhappy removing first 7 characters of directory names

Hi, I'm relatively new to unix, and would like to change the following files in a particular directory. The files have names like:

M10_90_Phcn402_3F.ab1
M10_94_Sput402_3F.ab1
M11_92_Abrg402_3R.ab1
M10_91_Cdel402_3F.ab1
M11_90_Phcn402_3R.ab1
M12_84_Sput402_3R.ab1
M10_93_Ehdr402_3F.ab1
M11_71_Cdel402_3R.ab1
M12_95_Epic402_3R.ab1

I would like to remove the first 7 characters of each file. For instance, in the first one, I would like M10_90_ to be removed, so the file name becomes Phcn402_3F.ab1

I have been playing with:

for x in M1*;do mv $x ${x/nnn/};done

I'm not sure what the correct expression is to remove the first 7 characters (not sure what to put in place of "nnn"). Is there a fast way to do this, or is there a different way to do this, maybe with "rename"?

Thanks

Last edited by euspilapteryx; 10-17-2009 at 07:31 PM..
  #2 (permalink)  
Old 10-17-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,129
#!/bin/ksh for i in M1* do echo mv "${i}" "${i##???????}" done
-->
Code:
#!/bin/ksh
for i in M1*
do
   echo mv "${i}" "${i##???????}"
done
        
Once satisfied with the echo-ed results, remove the 'echo'
  #3 (permalink)  
Old 10-17-2009
Scrutinizer Scrutinizer is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 722
To remove up to and including the second underscore:
mv "$x" "${x#*_*_}"
-->
Code:
mv "$x" "${x#*_*_}"
        
  #4 (permalink)  
Old 10-21-2009
euspilapteryx euspilapteryx is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 7
Thanks, this is really useful!
  #5 (permalink)  
Old 10-22-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 455
How about rename ?

rename 's/(.){7}//' *.ab1
-->
Code:
rename 's/(.){7}//' *.ab1
        
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0