把所有偶数行替换为---seq 5 | sed '__________'1---3---5
查看答案
在文件foo.txt的每两行之后添加来自文件address.txt的一行内容$ cat foo.txtbla bla 2015 blablah 2018 blahbla bla blacopyright: 2020$ cat address.txtstart address: 0xA0, func1 address: 0xA0end address: 0xFF, func2 address: 0xB0$ sed -n 'p' address.txt | sed -e '________________' foo.txtbla bla 2015 blablah 2018 blahstart address: 0xA0, func1 address: 0xA0bla bla blacopyright: 2020end address: 0xFF, func2 address: 0xB0
在文件address.txt的每一行前插入一行"---",并且在其后添加来自文件map.txt的一行。$ cat map.txt0xA0 0x50000xB0 0x60000xFF 0x7000$ sed ___________________ address.txt---start address: 0xA0, func1 address: 0xA00xA0 0x5000---end address: 0xFF, func2 address: 0xB00xB0 0x6000
文件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