Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何在文件中的特定字符串附近追加字符串?_Linux_Bash_Shell_Unix_Sed - Fatal编程技术网

Linux 如何在文件中的特定字符串附近追加字符串?

Linux 如何在文件中的特定字符串附近追加字符串?,linux,bash,shell,unix,sed,Linux,Bash,Shell,Unix,Sed,我想在文件中的特定字符串之后追加一个字符串,但不想在新行中追加 例如,我想在=之后添加两个 在执行文件之前: one two= three four five one two=two three four five 执行文件后: one two= three four five one two=two three four five 如何使用sed命令执行此操作?假设您希望在适当的位置执行此操作: sed -i 's/=/=two/' /path/to/file 它执行搜索和替换;找到

我想在文件中的特定字符串之后追加一个字符串,但不想在新行中追加

例如,我想在
=
之后添加
两个

在执行文件之前:

one
two=
three
four
five
one
two=two
three
four
five
执行文件后:

one
two=
three
four
five
one
two=two
three
four
five

如何使用sed命令执行此操作?

假设您希望在适当的位置执行此操作:

sed -i 's/=/=two/' /path/to/file
它执行搜索和替换;找到的相等项将替换为=2

如果您想保留原始版本的备份,只需在-i之后添加一个扩展,例如

sed -i.bak 's/=/=two/' /path/to/file

假设您希望在适当的位置执行此操作:

sed -i 's/=/=two/' /path/to/file
它执行搜索和替换;找到的相等项将替换为=2

如果您想保留原始版本的备份,只需在-i之后添加一个扩展,例如

sed -i.bak 's/=/=two/' /path/to/file

你可以使用:
sed's/=/&two/'文件
谢谢@anubhava这是我想要的。你可以使用:
sed's/=/&two/'文件
谢谢@anubhava这是我想要的。