syam.gadde
BIAC Staff
    
USA
421 Posts |
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!
|
 |
|