The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trying to remove '^M' characters from a file. Krispy Shell Programming and Scripting 13 05-12-2009 06:46 PM
Truncate last <n> characters from a file Gwailo88 UNIX for Dummies Questions & Answers 1 03-05-2008 12:52 AM
funny characters at the end of file achieve Shell Programming and Scripting 3 09-14-2006 05:39 AM
Reading Characters from txt file TexasGuy Shell Programming and Scripting 7 03-05-2005 07:14 PM
grepping the first 3 characters from a file rachael UNIX for Dummies Questions & Answers 2 10-15-2001 03:33 PM

Closed Thread
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 06-15-2008
Sabbybindy Sabbybindy is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 1
Swop postions of characters in a file name

Im hoping someone here can help me with the following please?!

I need to change the position of 3 characters in a set of file names.

I have the follow file name structure c2pMOW051102_winds.nc. I need to change the position of the characters c2p to MOW051102c2p_winds.nc.

Can this be done using the 'sed' command? Or does any one know any other way of doing this?

Thanks for any help!
  #2 (permalink)  
Old 06-15-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,447
Sed:

Code:
sed 's/\(.\{3\}\)\(.\{9\}\)\(.*\)/\2\1\3/'


Last edited by danmero; 06-15-2008 at 05:05 PM..
  #3 (permalink)  
Old 06-15-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
With shell:


Code:
for f in *.nc; do
  t="${f#???}" p="${f%$t}_" h="${t%_*}$p" r="${f#*_}"
  mv "$f" "$h$r"
done

Closed Thread

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 05:07 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