开发者

Using wildcards in sed command

开发者 https://www.devze.com 2023-03-23 15:39 出处:网络
The following command works as expected and changes the username to abc sed -e \'s/username=company_user/username=abc/\' Service.properties

The following command works as expected and changes the username to abc

sed -e 's/username=company_user/username=abc/' Service.properties 

But if the username is something different other than 'company_user' it will fail for obvi开发者_运维问答ous reasons. How do I use wildcards here?


It depends on what is a valid username, but here's a start:

sed 's/username=[a-z0-9_]+/username=abc/i' Service.properties

This will replace any username consisting of upper or lower case letters (note the i at the end, which makes the pattern case-insensitive), numbers and/or underscores with "abc". If you need to add other characters, just add them within the [].

0

精彩评论

暂无评论...
验证码 换一张
取 消