Duke-UNC Brain Imaging and Analysis Center
BIAC Forums | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Support Forums
 Unix Support
 batching renaming files

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
ch186 Posted - Jan 17 2014 : 10:14:49 AM
Hi-

I am trying to rename my files by deleting the dates out of the middle of the names. I have been trying to "rename" command and looking at the documentation online but haven't figured it out yet. Anyone know the easiest way to do this?

I have a bunch of files named FOO_DATE_SCANNUM_FA.nii.gz and want to get the date deleted out of the name. The date is in the exact space for each file (characters 4-12).
2   L A T E S T    R E P L I E S    (Newest First)
ch186 Posted - Jan 17 2014 : 10:40:27 AM
Thanks Syam, worked perfectly. I tried "sed" at first but always get confused when the sed gets that complicated :)
syam.gadde Posted - Jan 17 2014 : 10:35:25 AM
'rename' probably won't be as useful, as you need to know the actual string you want to replace, and if you know that already, you might as well use 'mv'.

You can try this, which checks for 8 numbers in the second underscore-separated field and removes it:

for filename in *.nii.gz ; do
newfilename=`echo "${filename}" | sed -e 's/^\([^_]*\)_[0-9]*_/\1_/g'`
echo mv "${filename}" "${newfilename}"
done

Another option is:

for filename in *.nii.gz ; do
newfilename=`echo "${filename}" | cut --complement -d _ -f 2`;
echo mv "${filename}" "${newfilename}";
done

This one is not as safe, as it might remove things that aren't actually 8 numbers (surrounded by underscores).

For safety, both of the examples above just print out the commands. If they look OK, you can get rid of the "echo" in the "echo mv" commands, and it will actually do the renaming. Be careful!

BIAC Forums © 2000-2010 Brain Imaging and Analysis Center Go To Top Of Page
This page was generated in 0.38 seconds. Snitz Forums 2000