• 本页内容

25. sed 注释


sed 注释以 # 开头。 我们都知道 sed 使用非常神秘的语言。 如果您在很长一段时间后查看它们,您今天编写的 sed 命令可能会看起来很陌生。

因此,建议在 sed 脚本文件中使用注释记录您的解释,如下所示。

$ vi mycommands.sed
# Swap field 1 (employee id) with field 2 (employee name)
s/\([^,]*\),\([^,]*\),\(.*\).*/\2,\1,\3/g
# Enclose the whole line within < and >
s/^.*/<&>/
# Replace Developer with IT Manager
s/Developer/IT Manager/
# Replace Manager with Director
s/Manager/Director/

注意:如果 *.sed 脚本中第一行的前 2 个字符是 #n,sed 将自动使用 -n(不打印模式缓冲区)选项。