Life is Struggle

利用 Sed 做字串的多筆取代

argv=$(echo ${MOBILES} | sed “s/ /@@/g”)

1
2
3
4
MOBILES="0988222784 0911070610 0916928508 0910081920"
# 將號嗎間的空白改由 @@ 取代, 這樣多筆才能順利傳進 php 裡
#argv=${MOBILES/ /@@} 這樣寫只能取代一次
argv=$(echo ${MOBILES} | sed "s/ /@@/g”) 

Grep 筆記

grep 某 pattern 時, 帶出前或後 n 行

含前二行 -B 2 (B:before)

1
cat /home/logs/php/vlog_patch.log | grep -B 2 'different'

含後二行 -A 2 (A:after)

1
cat /home/logs/php/vlog_patch.log | grep -A 2 'different'