如何用]替换文档中的最后一个字符?

时间:2018-10-12 12:11:36

标签: fish

如何用]替换文件的最后一个字符?

例如,如果文档内容如下:

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]

1 个答案:

答案 0 :(得分:3)

您可以指定行号,范围,甚至是要执行搜索并用sed替换操作的最后一行:

这将在最后一行中将,的最后一个]字符替换为sed '$ s/,$/]/'

$

在这里,sed字符告诉sed '1 s/,$/]/'仅在最后一行替换。

sed '1,4 s/,$/]/'命令仅在第1行上执行,&PICO_DWARF_I2C1 { status = "okay"; goodix: gt811@38 { compatible = "goodix,gt811"; interrupts = <GPIO_NO(PICO_EXT_GPIO_P44) 2>; reset-gpios = <GPIO_NO(PICO_EXT_GPIO_P32) GPIO_ACTIVE_LOW>; touchscreen-size-x = <1024>; touchscreen-size-y = <600>; }; }; 命令在第1至4行上执行。