sed练习题
问题1:输出oldboy. txt的第2-3行内容※。问题2:过滤出含有oldboy字符串的行※。问题3:删除含有oldboy字符串的行※。问题4:将文件中的oldboy字符串全部替换为oldgirl※。问题5:将文件中的oldboy字符串全部替换为oldgirl,同时将QQ号码49000448改为31333741.
1、输出oldboy. txt的第2-3行内容※。
[root@oldboyedu ~/test]# sed –n ‘2,3p’oldboy.txtI teach linux.
2、过滤出含有oldboy字符串的行※。
[root@oldboyedu ~/test]# sed -n '/oldboy/p' oldboy.txtI am oldboy teacher!our site is http://www. oldboyedu.commv god,i am not oldboy,but OLDBOY!
3、删除含有oldboy字符串的行※。
[root@oldboyedu ~/test]# sed '/oldboy/d' oldboy.txt I teach linux.I like badminton ball,billiard ball and chinese chess!mv qq num is 49000448not 490000448
4、将文件中的oldboy字符串全部替换为oldgirl※。
[root@oldboyedu ~/test]# sed 's#oldboy#oldgirl#g' oldboy.txt I am oldgirl teacher!I teach linux.I like badminton ball,billiard ball and chinese chess!our site is http://www. oldgirledu.commv qq num is 49000448not 490000448mv god,i am not oldgirl,but OLDBOY!
5、将文件中的oldboy字符串全部替换为oldgirl,同时将QQ号码49000448改为31333741.
[root@oldboyedu ~/test]# sed -e 's#oldboy#oldgirl#g' -e 's#49000448#31333741#g' oldboy.txt I am oldgirl teacher!I teach linux.I like badminton ball,billiard ball and chinese chess!our site is http://www. oldgirledu.commv qq num is 31333741not 490000448mv god,i am not oldgirl,but OLDBOY!