bash - 替换文本文件中的一行

标签 bash file shell sed

我有一个包含一行的文本文件

default_color acolor

我想用

替换这一行
default_color anothercolor

我不知道第一种颜色,第二种颜色包含在一个变量中。 我怎样才能在 bash 中做到这一点?

谢谢

最佳答案

它不是纯粹的 bash,但如果你有其他控制台工具,试试类似的东西

cat your_file | sed "s/default_color\ .*/default_color\ $VAR/"

关于bash - 替换文本文件中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1780200/

相关文章:

linux - 在 bash shell 中用零填充添加两个数字

python - 如何将python float转换为要在C++程序中解释的字节

javascript - 将文件作为 JSON 上传到 Python Web 服务器

shell - 测试 POSIX shell 合规性?

shell - 在 makefile 中转义

linux - 如何确定字符串是否包含awk的子字符串

bash - 在unix中排序日期字段

每次循环后 Python 保存到磁盘的速度变慢

linux - 如何将 init.d 脚本从 Ubuntu/Debian Linux 转换到 Solaris?

regex - 提取 bash 脚本中文件的两个表达式之间的行(使用 regexp、sed)