Command line interface

Compilation of occasionaly useful command line tools such as awk, sed and grep.

AWK commands

Awk is useful to modify existing tabulated data into new formats.

e.g extract only columns 1, 2, 4, and 5 to a new file

awk '{print $1" " $2" " $4" " $5}' infile.dat > outfile.dat

extract colums given condition; e.g. extract lines only if entries in 4th column are positive

awk '$4>0{print $1" " $2" " $4" " $5}' infile.dat > outfile.dat

split column entry by delimiter and write in new column

awk '{split($6,a,"_"); print $1" " $2" " $4" " $5, a[1], a[2]}' infile.dat > outfile.dat

telling AWK to ignore first 2 lines

awk 'NR>2{print $1" " $2" " $4" " $5}' infile.dat > outfile.dat

condition depending on value difference between two adjacent lines

e.g. extract lines if previous line has number that is by 3 smaller than current line; save difference as last collumn

awk '($2-p)>3{print $1" " $2" " $4" " $5 " " $2-p}{p=$2}' infile.dat > outfile.dat

pass arguments to AWK

awk -v phi='$phi' -v i='$i' {print $1" " $2" " i " " phi}' infile.dat > outfile.dat

GREP commands

Grep is useful to extract information from obtained data, or find specific words in data.

GREP extension to PDF's

For searching in text-based PDF's you can use simmilar utility called pdfgrep (does not come installed by default usually)

pdfgrep 統計力学 ./*/*pdf
./2013/gp2013-1A.pdf:                              『統計力学』の登場を待たな

SED commands

Sed is useful for creating scripts with large part of default values that can later be changed.

substitute placeholder string in document

sed -i "s|InputPorosity|$f|g" filename.dat