文件hello.txt的内容如下:$ cat hello.txtHello WorldHow are youThis game is goodToday is sunny12345You are funny请用sed对该文件做如下处理:如果某行包含"e",则把所有连续的重复字符变成大写并用{}括起来如果某行不包含"e",但包含"u"则将该行所有大写字母用[]括起来# 注意:第二行的H和最后一行的Y没有被修改$ sed -r '_____________________________________' hello.txtHe{LL}o WorldHow are youThis game is g{OO}d[T]oday is sunny12345You are fu{NN}y
查看答案
输入行包含多个用空格分隔的字段,第一个字段包含一些用"-"分隔的数,请将第一个字段中的这些数用"[]"括起来。$ echo '281-81-883 92-5 two' | sed -r '___________________________________'[281]-[81]-[883] 92-5 two
文件titles.txt的每行包含一个标题:以一个或多个"#"开头,后跟一个空格,然后是标题内容。现在需要把这些标题转化成链接形式:$ cat titles.txt# Linux Kernel## Bash Shell## The free software fundation$ sed -r '________________________________________________________' titles.txt# Linux Kernel## Bash Shell## The free software fundation
打印文件tb.txt中所有位于标记top和bottom之间的行。第一条sed命令有问题,因为sed在找不到第二个地址时会一直匹配到文件结尾$ cat tb.txttop38.1bottomtop9485bottomtophello worldhow are you# 错误输出$ sed -n '/top/,/bottom/ {//!p}' tb.txt38.19485hello worldhow are you# 正确输出$ sed -nr '______________________________________________' tb.txt38.19485
对文件hello.txt,将出现在标记How和12345之间的行替换为文件address.txt的内容。$ cat hello.txtHello WorldHow are youThis game is goodToday is sunny12345You are funny$ cat address.txtstart address: 0xA0, func1 address: 0xA0end address: 0xFF, func2 address: 0xB0$ sed -e '__________________________________________' hello.txtHello WorldHow are youstart address: 0xA0, func1 address: 0xA0end address: 0xFF, func2 address: 0xB012345You are funny