1.字元串 大小寫轉換
awk
toupper 小寫轉大寫
tolower 大寫轉小寫。
~ # cat /etc/firmware/nvram.txt | grep mac
macaddr=00:90:4c:c5:12:38
~ # cat /etc/firmware/nvram.txt | grep mac | awk -F '=' '{print toupper($2)}'
00:90:4C:C5:12:38
~ #
2.字元被替換為空
sed 's/被替換的字元//g'
删除 -,空格,:,特殊字元
~ # echo "2006-11-21 22:16:30" | sed 's/-//g'
20061121 22:16:30
~ # echo "2006-11-21 22:16:30" | sed 's/ //g'
2006-11-2122:16:30
~ # echo "2006-11-21 22:16:30" | sed 's/://g'
2006-11-21 221630
~ #
~ # echo "2006-11-21 22:16:30" | sed 's/-//g' | sed 's/ //g' | sed 's/://g'
20061121221630
~ #
~ #
将目前目錄下包含hello串的檔案中,hello字元串替換為hi
将某個檔案中的hello字元串替換為h
sed -i "s/hello/hi/g" test.txt
删除行首空格
删除行尾空格
FormUrl