i 代表 insert,在某行前插入内容;a 代表 append,在某行后追加内容。 三、sed 其他常见操作 🌟 修改某一行 语法: 复制 sed'3c\ This is a new line'file.txt 1. 3c\ :表示修改第 3 行 "This is a new line" : 替换的新内容 最终效果:第 3 行的内容会被 "This is a new line" 替换 示例:...
sed持有两段数据缓冲区:模式空间(pattern space)和保持空间(hold space)。 sed会对文件的每一行做以下循环:首先,sed从输入流中读取一行数据,移除任何结尾的换行符(newline),然后将其放入模式空间中。然后执行命令;每一个命令,可以有与之关联的地址:地址就是一种条件码,只有在条件符合的情况下,那么命令才会被执行。
[root@edenluo.com ~]# sed '[address][i | a]\newline' file newline 中的文本即为将要插入或附加在一行前面或后面的文本。常常使用这两个命令结合行寻址在特定的行前面或后面增加一个新行。 [root@edenluo.com ~]# sed 'i\Insert a line behind every line' /etc/passwd # 向数据流的每一行前面...
sed '[address][i | a]newline' file newline中的文本即为将要插入或附加在一行前面或后面的文本。常常使用这两个命令结合行寻址在特定的行前面或后面增加一个新行。举个例子: sed 'iInsert a line behind every line' /etc/passwd# 向数据流的每一行前面增加一个新行,新行的内容为 后面的内容 sed '1i...
P 印出 pattern space 内第一个 newline 字母 \ 前的资料。 q 跳出 sed 编辑。 r 读入它档内容。 s 替换字串。 t label 先执行一替换的编辑指令 , 如果替换成牛p>则将编辑指令跳至 : label 处执行。 w 写资料到它档内。 x 交换 hold space 与 pattern space 内容。
新建名为insert.sed的脚本,内容如下: Bash代码 1. #!/bin/sed -f 2. # this is comment 3. # date : 2013/06/02 4. # author : xiongneng 5. /this is/i\ 6. We insert a new line #插入的文本内容 2. 修改文本 修改文本是指将所匹配的问本行用新文本代替,也就是只能整行替换,sed修改文...
N :添加下一笔资料到 pattern space。 p :印出资料。 P :印出 pattern space 内第一个 newline 字母 前的资料。 q :跳出 sed 编辑。 r :读入它档内容。 s :替换字串。 w :写资料到它档内。 x :交换 hold space 与 pattern space 内容。 y :转换(transform)字元。上...
P 印出 pattern space 内第一个 newline 字母 \ 前的资料。 q 跳出 sed 编辑。 r 读入它档内容。 s 替换字串。 t label 先执行一替换的编辑指令 , 如果替换成牛p>则将编辑指令跳至 : label 处执行。 w 写资料到它档内。 x 交换 hold space 与 pattern space 内容。
不过官方的man文件里不是这样解释的,man文件里是这样解释的:复制代码代码如下:a \text Append text, which has each embedded newline preceded by a backslash.i \text Insert text, which has each embedded newline preceded by a backslash.而且其可以配合find查找的内容处理,如下:复制代码代码...
= Print the current line number.a \text Append text, which has each embedded newline preceded by a backslash.i \text Insert text, which has each embedded newline preceded by a backslash.r filename Append text read from filename.R filename Append a line read from filename. Each invocation...