Content #
等号命令会打印文本行在数据流中的行号。行号由数据流中的换行符决定。数据流中每出现一个换行符,sed编辑器就会认为有一行文本结束了: $ cat data1.txt The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. $ $ sed ‘=’ data1.txt 1 The quick brown fox jumps over the lazy dog. 2 The quick brown fox jumps over the lazy dog. 3 The quick brown fox jumps over the lazy dog. 4 The quick brown fox jumps over the lazy dog. $ sed编辑器在实际文本行之前会先打印行号。如果要在数据流中查找特定文本,那么等号命令用起来非常方便: $ cat data7.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. This is line number 1 again; we want to keep it. This is more text we want to keep. Last line in the file; we want to keep it. $ $ sed -n ‘/text/{ > = > p > }’ data7.txt 6 This is more text we want to keep. $ 利用-n选项,就能让sed编辑器只显示包含匹配文本模式的文本行的行号和内容。
From #
Linux命令行与shell脚本编程大全