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
sed -i "s/hello/hi/g" `grep "hello" -rl ./`
将某个文件中的hello字符串替换为h
sed -i "s/hello/hi/g" test.txt
删除行首空格
sed -i 's/^ //g' test
删除行尾空格
sed -i 's/ $//g' test