将以字母a或r结尾的单词后跟的空白符替换成换行符:$ echo 'ada not a _cn_ addr street 23' | sed -e '___________'adanot a_cn_ addrstreet 23
查看答案
用一次替换完成以下操作:把所有单词用小括号括起来,如果单词是fish或egg则将其删除:$ echo 'apple fish pear mango egg banana' | sed -r '__________________'(apple) () (pear) (mango) () (banana)
输入为用,分隔的多个字段,其中有些字段可以为空,请使用sed将第3个字段的内容替换为39。$ echo 'desk,,,window,chair' | sed -E '_____________'desk,,39,window,chair
将除了前两次匹配的所有a替换为7。$ echo 'hear have Isaac eagar' | sed -e '_____________'hear have Is77c e7g7r
将文件 tao.txt 中所有行替换为该行的字符数(命令wc -L可以获得行的长度)$ cat tao.txtTao of computer scienceIf the Tao is great,then the operating system is good.If the operating system is great,then the compiler is great.If the compiler is great,then the application is great.The user is pleased,and there is harmony in the world.$ sed -ne '_____________________' tao.txt232034332725302034