Kwonsnow
by Kwonsnow

Categories

Tags

shell is not a programing language, but just collection of different programs. Normally they works together very well.

[AB] : A or B
*: 모든 character를 모를 때
?: 한개의 character만 모를 때

“$1”, “$2”, “$3”, … are equivalent to sys.argv[1], sys.argv[2], sys.argv[3], …

for 문

for filename in $(find ./ -name “KPOINTS”)
do
echo “$filename”
head -n 3 “$filename” | tail -n 1
done

(for filename in $(find ./ -name KPOINTS sort); do echo $filename; head -n 3 $filename tail -n 1; done)

./n-0.2/KPOINTS
Monkhorst-pack
./n-0.3/KPOINTS
Monkhorst-pack
./n-0.4/KPOINTS
Monkhorst-pack
./n-0.5/KPOINTS
Monkhorst-pack

for filename in $(find ./ -name log sort); do grep mag $filename tail -n 1; done

1 F= -.13482145E+04 E0= -.13482186E+04 d E =-.134821E+04 mag= 0.9793
6 F= -.13492122E+04 E0= -.13492093E+04 d E =-.452426E-04 mag= -0.8000
80 F= -.13501763E+04 E0= -.13501718E+04 d E =-.643308E-04 mag= 0.6000
13 F= -.13510909E+04 E0= -.13510864E+04 d E =-.239923E-04 mag= -0.4000
29 F= -.13519713E+04 E0= -.13519685E+04 d E =-.186061E-04 mag= 0.2000
10 F= -.13528179E+04 E0= -.13528197E+04 d E =-.243613E-04 mag= -0.0380
9 F= -.13534859E+04 E0= -.13534878E+04 d E =-.329962E-04 mag= -0.3236
. 5 F= -.13541361E+04 E0= -.13541365E+04 d E =-.525833E-04 mag= -0.5353
7 F= -.13547660E+04 E0= -.13547653E+04 d E =-.899295E-04 mag= -0.7299
123 F= -.13554384E+04 E0= -.13554377E+04 d E =-.247668E-04 mag= 0.9213
6 F= -.13560312E+04 E0= -.13560309E+04 d E =-.121462E-03 mag= 1.1279

command line에서 모든 argv를 받고 싶을 때, “$@” 사용.
for filename in “$@”
do
head -n 2 “$filename” | tail -n 1
done

bash loop.sh *.bgf

if 문

num = $(wc -l $1)
if [“$num” -gt “5”]
then
echo $1 “is big enough”
fi
bash 비교연산자

wc

wc command : line, word, character
wc - l *.pdb > text.txt
sort -n text.txt

grep

grep NELECT $(find ./ -name INCAR | sort)

./n-0.2/INCAR:NELECT = 204.8
./n-0.3/INCAR:NELECT = 204.7
./n-0.4/INCAR:NELECT = 204.6
./n-0.5/INCAR:NELECT = 204.5

awk

date

date “+%F”

2021-03-22