| 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!
|
|
|