2016年4月21日 星期四

Linux 文字改寫的好幫手 sed

文字改寫的好幫手

文字替換

[root@rhel7 ~]# echo abcd |sed s/a/z/
zbcd
#文字替換
[root@rhel7 ~]# echo "abcd" |sed "s/a/z/"
zbcd
#引號
view raw 20160422A01.sh hosted with ❤ by GitHub
[root@rhel7 ~]# echo old old | sed s/old/new/g
new new
#文字替換
[root@rhel7 ~]# echo "abcd" |sed "s/a/z/"
zbcd
view raw 20160422A02.sh hosted with ❤ by GitHub
[root@rhel7 ~]# echo "this is bad" | sed 's/bad/good/w out.txt'
this is good
#替換文件內文字
[root@rhel7 ~]# cat out.txt
this is good
#查看結果
view raw 20160422A03.sh hosted with ❤ by GitHub
[root@rhel7 ~]# echo "今天心情很差" | sed s/差/好/g
今天心情很好
#中文範例
view raw 20160422A04.sh hosted with ❤ by GitHub

沒有留言: