如何将文件的最后一个字符替换为 ] ?
]
例如,如果文档内容如下所示:
This is the first line with a full stop. This is the second line with a full stop. This is the third line with square bracket.
This is the first line with a full stop. This is the second line with a full stop. This is the third line with square bracket]
您可以指定行号、范围,甚至是要执行搜索和替换操作的最后一行 sed
sed
, ] 只有 最后一行:
,
sed '$ s/,$/]/'
这里,那个 $ char告诉我们 只替换最后一行。
$
这个 sed '1 s/,$/]/' 命令只能在第1行执行,并且 sed '1,4 s/,$/]/'
sed '1 s/,$/]/'
sed '1,4 s/,$/]/'