shell scriptで便利な機能一覧
権限変更
chmod u+x "filename"
実行
./"filename"
[引数]
ファイルの中で第n引数が$nで使える。$#で引数の数がわかる。$*で全部の引数。
[変数]
ファイルの中で変数を使うにはdeclareで宣言が必要。
オプション
-i 整数
[ファイルから一行ずつ読み込み]
while read i
do
echo ${i}
done < hello.txt
便利なコマンド
10行目から15行目まで抜き出し
head -15 "filename" | tail -5
文字検索
grep
オプション
-r 再帰的検索
-n 検索文字が何行目か表示
文字抜き出し
cut
オプション
-d 区切り方指定(e.g. -d" " ←スペース指定)
-f どこを抜き出すか(e.g. -f1,11 ←1番目と11番目)
文字変換1
tr "char1" "char2"
char1をchar2に変換
文字変換2
sed -e "s/char1/char2/g"
char1をchar2に変換
オプション
-n 行数指定(e.g. sed -n 10,15p)
最終更新:2010年02月12日 11:19