击:在一个文件中更新变量 [英] Bash: Update a variable within a file

查看:110
本文介绍了击:在一个文件中更新变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个简单的答案,我大概可以保持对谷歌挖四周之前,我通过这个答案漫步。但我在紧张的日程,我希望一个简单的回应。

我需要在安装更新的ifcfg-eth0的一个变量。因此,换句话说,这是需要做些什么:

下面的变量需要从改变:

  ONBOOT =无
BOOTPROTO = DHCP

  ONBOOT = YES
BOOTPROTO =静态

在此先感谢!

干杯。


解决方案

  SED -i -e'/ ^ ONBOOT = /秒| * | ONBOOT = YES |。 / ^ BOOTPROTO = / S | * | BOOTPROTO =静态|'文件

相关搜索

  SED -i -re的| ^(ONBOOT =)* | \\ 1yes |。 S | ^(BOOTPROTO =)* | \\ 1静态|'文件

或者

  SED -i -e的| ^ \\(ONBOOT = \\)* | \\ 1yes |。 S | ^ \\(BOOTPROTO = \\)。* | \\ 1静态|'文件

I know this is a simple answer and I could probably keep digging around on Google before I stroll across the answer. But I am on a tight schedule and I was hoping for an easy response.

I need to update a variable in ifcfg-eth0 upon an installation. So in other words, this is what needs to happen:

The following variables need to change from:

ONBOOT=no
BOOTPROTO=dhcp

to

ONBOOT=yes
BOOTPROTO=static

Thanks in advance!

Cheers.

解决方案

sed -i -e '/^ONBOOT=/s|.*|ONBOOT=yes|; /^BOOTPROTO=/s|.*|BOOTPROTO=static|' file

Also try:

sed -i -re 's|^(ONBOOT=).*|\1yes|; s|^(BOOTPROTO=).*|\1static|' file

Or

sed -i -e 's|^\(ONBOOT=\).*|\1yes|; s|^\(BOOTPROTO=\).*|\1static|' file

这篇关于击:在一个文件中更新变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆