# 示例代码:使用 sed 命令替换文件中的字符串
# 替换单行中的内容(直接输出到终端)
echo "Hello World" | sed 's/World/Linux/'
# 解释:上述命令会将 "Hello World" 中的 "World" 替换为 "Linux",并输出结果 "Hello Linux"。
# 在文件中进行替换(原地修改文件)
sed -i 's/old_string/new_string/g' filename
# 解释:上述命令会在文件 filename 中将所有的 "old_string" 替换为 "new_string"。'-i' 选项表示直接在文件中进行修改,'g' 表示全局替换(即替换每一行中的所有匹配项)。
# 替换指定行的内容
sed '2s/old_string/new_string/' filename
# 解释:上述命令只会替换文件中第 2 行的 "old_string" 为 "new_string"。
上一篇:echo在linux是什么意思
下一篇:linux iconv
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站