Unix shortcuts: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Unix scripting will save you time in the long run. Really! To do the same command, like zcore, for example, on a bunch of files, doing this in the command line, use a comm...") |
(No difference)
|
Latest revision as of 18:36, 6 November 2014
Unix scripting will save you time in the long run. Really!
To do the same command, like zcore, for example, on a bunch of files, doing this in the command line, use a command like this: for i in `ls -1 *.nii`; do echo $i; zscore.pl -i $i; done More complicated versions in a script: ext=’gz’ log=/dev/null; for i in `ls -1 *.$ext 2>$log`; do NAME=`basename $i .$ext`; echo “File: $NAME” ;echo “Moving $NAME.$ext to $NAME.$newext”; done
if you want to do more complicated things, changing names, for example, resort to perl. also, FYI, you can run a perl command in a single line on the command line. This is good for regular expression matching: name=`echo $FILENAME | perl -p -e ’s/(.+)\.gz/$1/i’`