Sunday, July 20, 2014

some imp commands to be edited later..


 perl -pi -e 's/batchSIFTflow1/batchSIFTflowUsingDecaf/g' myBatchSIFTFLowDecaf*.m
 grep  batchSIFTflowUsingDecaf myBatchSIFTFLowDeca*.m
 perl -pi -e 's/gistL2/DecafL2/g' myBatchSIFTFLowDecaf*.m
 diff myBatchSIFTflow16.m myBatchSIFTFLowDecaf16.m
 sed 's/flow1/flowUsingDecaf/g' myBatchSIFTflow16.m | sed 's/,1,/,20,/g' | sed 's/gistL2/DecafL2/g' > tmp
 diff myBatchSIFTflow16.m tmp
 for i in {1..47}; do sed 's/flow1/flowUsingDecaf/g' myBatchSIFTflow$i.m | sed 's/,1,/,20,/g' | sed 's/gistL2/DecafL2/g' > myBatchSIFTFLowDecaf$i.m; done

Replacing strings in a file

 perl -pi -e 's/pattern/patternToReplace/g' fileName.ext

for i in {2..200}; do
sed 's/xx/'$i'/g' template.m > select-$i.m
done

Counting the files in all sub drectories of a folder

Assumptions:
Given a directory; it has n subdirectories and does not have any files. The subdirectories jsut have files and no folders.
You want to count all the files in the n sub directories.

here's a shell script:
filecount=0;
for i in $(ls);
do
cd $i;
a=$(ls | wc -l) ;
filecount=$[filecount+a];
echo $filecount;
cd ..;
done

adding numbers is a bash script

num=$[num1+num2]
there are many more options, but this is the simplest.
Note no spaces between any of the characters above