[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] sed如何替换指定文本中的特定字符串

想要批量修改Linux 的一些配置文件
对sed不是太熟悉,找到了这个比较笨的方法,修改HOSTNAME成功了
可是修改SELINUX的配置文件确出了问题
  1. #sed -i '/HOSTNAME/d' /etc/sysconfig/network
  2. #echo  'HOSTNAME=testname' >> /etc/sysconfig/network
  3. #sed -i '/SELINUX/d' "/etc/selinux/config"
  4. #echo  'SELINUX=disablexxx' >> "/etc/selinux/config"
复制代码
  1. # This file controls the state of SELinux on the system.
  2. # SELINUX= can take one of these three values:
  3. #     enforcing - SELinux security policy is enforced.
  4. #     permissive - SELinux prints warnings instead of enforcing.
  5. #     disabled - No SELinux policy is loaded.
  6. SELINUX=enforcing
  7. # SELINUXTYPE= can take one of these two values:
  8. #     targeted - Targeted processes are protected,
  9. #     mls - Multi Level Security protection.
  10. SELINUXTYPE=targeted
复制代码
  1. # This file controls the state of SELinux on the system.
  2. #     enforcing - SELinux security policy is enforced.
  3. #     permissive - SELinux prints warnings instead of enforcing.
  4. #     disabled - No SELinux policy is loaded.
  5. #     targeted - Targeted processes are protected,
  6. #     mls - Multi Level Security protection.
  7. SELINUX=disablexxx
复制代码
修改完了,成了这样,后面的内容都被删除了。
正确的使用sed修改某个参数的方法是什么?

回复 3# DiamondbacK

好用多谢,试着理解理解我

TOP

返回列表