ok! This is getting interesting
Now my question is: where does the prefix come from?
Maybe it's like the directory is called 4001 for subject 4001
and 4002 for subject 4002?
Also: con does not change per subject right? Meaning: all files from all directories will get the _con part in it?
Do you want to be able to do multiple directories in one go? Is that an option? I'd try that if i were you since it saves alot of browsing the directories.
/edit: i have a working command for you if you just answered yes the the questions above:
A couple things:
1. first make a backup of the directories yourself!
2. i called the directory where you put all the renamed files: outputdir
You can change it to any name.
3. To create the outputdir (called outputdir) type this command:
4. when you execute this command i'm assuming you are one directory up of the subject-dirs.
So when you do a directory listing we should see this:
Code:
ls
4001 4002 4003 4004 outputdir
5. it will copy all *.img and *.hdr from all subdirectories, if want to exclude directories: let me know.
6. you could also put this command in a script. If you are interested in that, let me know.
7. for this 'problem' there are many possible solutions, i think this one works reasonably well.
8. in my earlier post i was using the move (mv) command, i think it is safer to use copy (cp), so i used it here.
9. I am assuming you named all the subject directories like so: 4001
And another patient directory could be called 4002
Anyways here is the command:
Code:
for i in `find . -name "*.img" -o -name "*.hdr"|grep -v outputdir`; do cp -i $i ./outputdir/`dirname $i |sed 's/^.\///g'``basename $i | sed 's/con_/_con/g'`; done
(make sure to COPY this command to your terminal since it contains backticks `` that can be easily missed when typing by hand.
To paste it in your terminal do a middle-mouse button click or paste with right-click)
Explanation:
for i in `find . -name "*.img" -o -name "*.hdr"|grep -v outputdir`;
find all files with extensions .hdr and .img in all subdirectories. Exclude the output directory (since it may also contain files from previous runs) with grep.
-------------------------------------------------------------------
do cp -i $i
copy the file from its original location to
(the -i option is to specify that we don't want to overwrite any files in the outputdir so
if a file already exists it will prompt you with a question whether to overwrite or not)
./outputdir/
(copy to) ./outputdir specifies the output directory that will contain all copied&renamed files.
`dirname $i |sed 's/^.\///g'`
take the original directory-name, it will output the patient prefixes like 4001. Strip the leading ./ with sed to give a name like 4001
`basename $i | sed 's/con_/_con/g'`;
specify the name of the file to copy to. Replace con_ with _con
done
-------------------------------------------------------------------
sources:
http://www.splike.com/howtos/bash_fa...sion%2C+etc%3F
Off-topic: mri rules! I was a subject for a study into gambling-addiction this year, i think it was mostly structural mri.
For the record: i'm was one of the negative-test-group :P
I'm interested whether this solution works for you, if have questions feel free to ask!