0

I would like to export the data values generated on Terminal into CSV file, following is the output that i obtain after executing an instruction in Freesurfer

dev@dev-OptiPlex-780:~$ mri_segstats --subject Sub1 --etiv-only

    $Id: mri_segstats.c,v 1.75.2.9 2013/02/16 00:09:33 greve Exp $
    cwd 
    cmdline mri_segstats --subject Sub1 --etiv-only 
    sysname  Linux
    hostname dev-OptiPlex-780
    machine  x86_64
    user     dev
    UseRobust  0
    atlas_icv (eTIV) = 1144730 mm^3    (det: 1.701803 )

From the above output ,I would like to extract the only the value of atlas_ICV(eTIV) (i.e = 1144730 mm^3) in a csv file using bash script ,any suggestions would be greatly appreciated.

I have written automated code for extracting ICV value for 10 subjects that i have in my directory

    for ICV in `cat list_subjects.txt`;do

    #mri_segstats --subject $ICV --etiv-only

   ICV_Calculation=mri_segstats --subject $ICV --etiv-only | sed -n 's/.*(eTIV) = \([0-9].*mm^3\).*/\1/p'

    echo "${Subjects_ICV},${ICV_Calculation}" >>Subjects_ICV.csv

    done

where list_subjects.txt includes all the subjects that i have in my directory

0

I would like to extract the only the value of atlas_ICV (eTIV) (i.e = 1144730 mm^3)

Given this file:

: mri_segstats.c,v 1.75.2.9 2013/02/16 00:09:33 greve Exp $
cwd 
cmdline mri_segstats --subject Sub1 --etiv-only 
sysname  Linux
hostname dev-OptiPlex-780
machine  x86_64
user     dev
UseRobust  0
atlas_icv (eTIV) = 1144730 mm^3    (det: 1.701803 )

I can use this sed:

sed -n 's/.*(eTIV) = \([0-9].*mm^3\).*/\1/p' atlas
1144730 mm^3

If you want to extract that value from output to STDOUT, just use a pipe, like so:

cat atlas | sed -n 's/.*(eTIV) = \([0-9].*mm^3\).*/\1/p'
1144730 mm^3

In your case I guess it would look like:

mri_segstats --subject Sub1 --etiv-only | sed -n 's/.*(eTIV) = \([0-9].*mm^3\).*/\1/p'

sed --version
sed (GNU sed) 4.2.2
  • I have small question The --subject Sub1 denotes only one subject, i have 10 subjects , how could i possibly run mri_segstats instruction for 10 subjects and extract ICV for each accordingly ? – DevanDevak Nov 3 '16 at 13:56
  • Unfortunately I have no idea, I don't know what mri_segstats is! – maulinglawns Nov 3 '16 at 13:57
  • mri_segstats is an normal instruction, when i install freesurfer -Brain imaging software, mri_segstats represents the statistical information after the MRI has undergone segmentation, i have written the code for segmentation and it calculates ICV values, I have 10 subjects and when i run the code mrisegstats on each subjects it generates ICV value, but i want an automated code ( like a for loop which can all subjects and generate ICV value). I have updated the code that i have written in the question ,please check – DevanDevak Nov 3 '16 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.