bash - 尝试在给定文件的每一行末尾添加一个字符,是如何完成的?

标签 bash shell

我有一个如下所示的文件:

sudo apt-get install rar
sudo apt-get install gimp
sudo apt-get install gnome-tweak-tool
sudo apt-get install unity-tweak-tool
sudo apt-get install pidgin

我想以某种方式在每行末尾添加“-y”,如何完成? 谢谢

最佳答案

sed -i 's:$: -y:' YOURFILE

会为你做的。

  1. -i“就地”进行修改,因此不会创建新文件(实际上有一个 tmp 文件)
  2. s替代品
  3. :分隔符
  4. $ 行尾
  5. 参见第 3 点
  6. -y 替换

关于bash - 尝试在给定文件的每一行末尾添加一个字符,是如何完成的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23603081/

相关文章:

linux - 如何修复: Unrecognized command error in Linux

linux - 将输出重定向到我的源文件因此丢失了我的源

用于在 AWK 中捕获具有一系列数字的数字的正则表达式

shell - 谁能完整解释这个命令 adb shell sendevent [device] [type] [code] [value]?

perl - 如何从 Perl 脚本调用 shell 函数?

linux - 在 bash 中使用先前命令的输出

linux - 如何在 shell 脚本中使用 tee 和 sshpass

bash - GNU 与可变序列并行?

bash - 在 shell 脚本中隐藏密码

c - 在 Unix 中如何处理 '<'?