Useful knowledge

Things I want to learn and magically forget. Useful in my work. Written down from Internet by Maciej Matyka

Nice colors

Linux

RamDisk

Codes

Anims

OGV to AVI

Porous Media

Links (Porous Media)

CUDA

  • --cuda-nvcc-opts="--compiler-bindir=/usr/bin/gcc-4.4"
  • Shell

    Random

  • Find string in group of .h and .c files: grep --include=\*.{C,h} -rnw './' -e "srand"
  • Calculations in bash

  • for L in 20 40 80 do A=$(echo $L/2.0 | bc ); done;
  • Grep + cut

  • grep "Computation" gpu.txt | cut -c 40-47 timegpu.txt
  • Cut a column from file (with space as delimiter): cut -d' ' -f2 single.dat
  • SED

  • sed -i 's/,/ /g' FILE
  • sed -i 's/,/./g' *.CSV
  • AWK

  • print last line from multiple files: for i in *.dat; do echo $i; awk '{ } END {print $1,$2,$3,$4}' $i; done;
  • AWK multiple files (file difference): awk 'BEGIN{i=0;j=0} NR==FNR{a1[i]=$1; a2[i]=$2; a3[i]=$3; i++;next} {b1[j]=$1;b2[j]=$2;b3[j]=$3;j++} END {for(k=0;k<i;k++) print a1[k]-b1[k], a2[k]-b2[k], a3[k]-b3[k]}' vel--30--4--5000000-double.vtk vel--30--4--5000000-single.vtk >roznica.awk
  • AWK get value of second column only if the value in first is less than in previous line+last line: awk '{ if(prev>$1) {print prev,prev13;}; prev=$1; prev13=$13; } END {print $1,$13;}' res-140--400-.dat-sort.dat
  • AWK get value of second column only if the value in first is less than in previous line: awk '{ if(prev>$1) {print prev,prev13;}; prev=$1; prev13=$13;}' res-140--400-.dat-sort.dat
  • AWK average + std error: awk 'pass==1 && $1=="50000" {print "pass1: ",$1; sumphi+=$6; sumalphasquared+=($13^2); n+=1} pass==2 && $1=="50000" {print "pass=2: ",$1; sumximinusmu+=(($13^2-sumalphasquared/n)^2)} END {print n,sumphi/n, sqrt(sumalphasquared/n), sqrt(sumximinusmu/n) / sqrt(n)}' pass=1 res-140.dat pass=2 res-140.dat
  • AWK Average + Std. Deviation: awk 'pass==1 && $1=="50000" {print "pass1: ",$1; sumphi+=$6; sumalphasquared+=($13^2); n+=1} pass==2 && $1=="50000" {print "pass=2: ",$1; sumximinusmu+=(($13^2-sumalphasquared/n)^2)} END {print n,sumphi/n, sqrt(sumalphasquared/n), sqrt(sumximinusmu/n)}' pass=1 res-140.dat pass=2 res-140.dat
  • for i in "1" "2"; do echo "$i" ; done
  • for f in $(seq 1 9); do echo kit$f; done
  • for f in *.dat; do awk '{ field = $NF }; END{ print field }' $f; done;
  • for f in *x*.dat; do echo -n $f " "; awk '{ field = $NF }; END{ print field }' $f; done;
  • awk 'NF > 0 { field = $NF }; END{ print field }' (by aln)
  • Fraction in BASH loop: for i in {0..20..1}; do alpha=$(echo "$i/10"|bc -l); echo $alpha; done
  • Average bash: awk '{if ($1 == "0.6") {sum+=$2; print $1,$2; N+=1} } END { print N, sum/N}' res.csv
  • min/max/average (http://blog.damiles.com/2008/10/awk-calculate-mean-min-and-max/): awk '{if(min==""){min=max=$1}; if($1 > max) {max=$1}; if($1<min) {min=$1}; total+=$1; count+=1} END {print total/count, min, max}' angle_10_100.dat
  • Using bash variables in AWK: for i in {0.6,0.62,0.64,0.66,0.68,0.7,0.72,0.74,0.76,0.78,0.80,0.82,0.84,0.86,0.88,0.90,0.92,0.94,0.96,0.98,1.0}; do awk -v i="$i" '{if ($1 == i) {sum+=$2; N+=1} } END { print i,sum/N}' res.csv; done
  • Simple average: awk '{sum+=$2; N+=1} END { print N, sum/N}' file.dat
  • cyclic elements in a table

    preprocessor

    torque


    Last Update: 2018-08-20 (Maciej Matyka)