28. Append Line After (a command)
你可以使用a命令在匹配到行后面添加新行
Syntax(语法)
|
|
Add a new record(记录)to the employee.txt file after line number:
对employee.txt文件在指定行号后面添加一个新的记录
29. Insert Line Before (i command)
使用i命令在匹配到行前面插入新行
Syntax(语法)
|
|
30. Change Line (c command)
使用c命令,修改匹配到的行
Syntax(语法)
|
|
31. Combine a, i, and c Commands(联合使用a,i,c命令)
|
|
32. Print Hidden Characters (l command)(显示隐藏字符)
例如\t tab字符,$行尾
执行l命令显示tab和EOL
当你在l命令后面指定一个数字n,则在匹配行的第n个字符处打印一个\
This works only on GNU sed.
12345678910 $ sed -n 'l 20' employee.txt101,John Doe,CEO$102,Jason Smith,IT \Manager$103,Raj Reddy,Sysad\min$104,Anand Ram,Devel\oper$105,Jane Miller,Sal\es Manager$
33. Print Line Numbers (= command)
打印行号
Print all line numbers
|
|
Print line numbers only for lines 1,2 and 3:
|
|
34. Change Case (using the y ‘transform’ command)
一对一替换,感觉用处不大。加密用?
In this example character “a” will be transformed to A, b to B, c to C, etc.:
|
|
35. Multiple Files in Command Line
可以在一行命令行下对多个文件使用同一个sed
36. Quit Sed (q command)
q命令是第一次匹配到行后退出
Note:
q命令对地址范围是无效的。因为匹配到第一行的时候就退出了
37. Read from File (r command)
读取文件,并将文本内容输出到标准输出
38. Simulating Unix commands in sed (cat, grep, head)
用sed模仿其他命令
39. Sed Command Line Options
-n option
静默模式,禁止默认的输出
You can also use --quiet, or –-silent instead of -n. They are identical in function.
我们也可以使用--quiet, or –-silent代替-n
-f option(--file option)
读取sed脚本
-e option(--expression option)
执行一个sed命令
-i option(-ibak等价于--in-place=bak)
替换选项,重写输入文件
-c option(和-i选项联合使用)
和-i联合使用,-ibak是备份原文件,加-c选项则是新建一个bak文件,将-i替换的文件写入新建文件。源文件不变
你也可以使用--copy选项。等价与-c
-l option(--line-length option)
指定行长度进行分割
40. Print Pattern Space (n command)注意,不是-n选项
读取下一行,并打印模式空间里的内容