aa
bb
cc
Hello world! Hello Jack!
Hello China!
Hello Nick!
$ test.txt # 删除第二行到最后一行
选项 -i
$ -i '1d' test.txt
$ test.txt # 在第一行下面新增一行,内容为 test.txt # 在最后一行下面新增一行,内容为 , test.txt # 一次增加多行需要使用换行符 \n
$ -e '1a xxx' -e '2a yyy' test.txt
1i Hello world!
2i Hello world!
3i Hello world!
$ -f commands test.txt
$ test.txt # 把第一行替换为 test.txt # 把第一行到第三行替换为
$ hello.txt # 把Hello 替换为 Hi
$ hello.txt # 把匹配到的所有Hello 都替换为 Hi
$ hello.txt # 只在第二行和第三行进行替换操作
$ hello.txt # 删除字符串 Hello
$ -n test.txt 和命令sed -n hello.txt
$ -n -n -n -n test.txt # 匹配第三行和第三行后的每一行
$ -n hello.txt
$ -n hello.txt
$ hello.txt # 找到匹配的行,在这些行中执行替换
$ -i -i my.cnf