如何更改 linux 命令中的特定行

how to change a specific line in the linux command

如何更改特定行的文本

假设我要更改第50行,我想更改"user"之后的8个字母: 就像下面我加粗的例子

第 50 行“用户”:“9077c266-8944-11eb-a9d1-fa163e4be1a2”

如果它是唯一的,我会按行号或内容使用 sed:

sed -i '50s/9077c266/replacement/' file.txt

或:

sed -i 's/9077c266/replacement/' file.txt

sed中使用s命令进行搜索和替换。

sed -i 'Ns/9077c266/replacement-line/' file.txt

其中 N 应替换为您的目标行号。

要将更改的文本保存在不同的文件中,请删除 -i 选项:

sed  'Ns/9077c266/replacement-line/' file.txt > new_file.txt