如何用]
替换文件的最后一个字符?
例如,如果文档内容如下:
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]
答案 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行上执行。