将除了前两次匹配的所有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
对于文件begin-end.txt,假设该文件总是包含行号为4的倍数的行,使用sed命令每次读入4行到模式空间,然后从第一次出现的行首的begin开始一直删除到end,并且不区分begin和end的大小写。$ sed -ne '____________________' begin-end.txtgood beginhi therebye
对于给定的字符串,将倒数第3个he替换成M,并且仅打印被替换操作改变了的行:echo 'he and she here head and ache' | sed -nr '_______________________'he and she Xre head and ache
仅打印文件hello.txt的第3行,并用-----上下包围该行:$ sed -ne _____________ hello.txt-----This game is good-----