sed在所选文本的第8个位置替换空格字符 [英] sed replace space character at the 8th position from selected text

查看:50
本文介绍了sed在所选文本的第8个位置替换空格字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们公司的dhcp服务器的配置文件中添加了一长串主机.

I have a long list of hosts added in the config file of the dhcp server for our company.

条目看起来像这样:

host s1 { hardware ethernet b4:e1:0f:06:cb:83; fixed-address 192.168.10.43; }
host s2 { hardware ethernet b4:e1:0f:06:cb:90; fixed-address 192.168.10.64; }
host s3 { hardware ethernet b4:e1:0f:06:cb:9d; fixed-address 192.168.10.44; }
host s4 { hardware ethernet b4:e1:0f:06:cb:aa; fixed-address 192.168.10.65; }
host s5 { hardware ethernet b4:e1:0f:06:cb:b7; fixed-address 192.168.10.41; }
host s6 { hardware ethernet b4:e1:0f:06:cb:c4; fixed-address 192.168.10.35; }
host s7 { hardware ethernet b4:e1:0f:06:cb:d1; fixed-address 192.168.10.36; }
host s8 { hardware ethernet b4:e1:0f:06:cb:de; fixed-address 192.168.10.67; }
host s9 { hardware ethernet b4:e1:0f:06:cb:eb; fixed-address 192.168.10.72; }

我正在使用vim编辑文件.我如何用.domain.com之类的内容替换位置8处的空格字符?(我指的是s1,s2等之后的空格char

I am editing the file using vim. How do i replace the space char at position 8 with something like .domain.com? (I am referring to the space char after s1,s2 etc

我用sed尝试了不同的配置和模式,但由于某种原因,我无法使其正常工作.

I have tried different configurations and patterns with sed but for some reason I cant' make it to work.

另一种方法是将空格+ {替换为我想要的,但这不是我想要的解决方案.

An alternative way would be to replace the space + { with what I want but this is not the solution I am looking for.

此致

推荐答案

您可以使用此 sed

sed 's/host [^ ]*/&.domain.com/g' file

这篇关于sed在所选文本的第8个位置替换空格字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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