regex - How to use grep command to list dot based names
问题描述
I am trying to grep some of the services but it does not print exactly what I am looking for.
One thing I see in the grep strings is that the names are having dot .
jointed names.
I am trying below but not getting the desired output.
# systemctl list-unit-files | egrep -w "autofs.service|sssd.service"
autofs.service disabled
sssd-autofs.service indirect
sssd.service disabled
or
# systemctl list-unit-files | egrep "autofs|sssd[.service]"
autofs.service disabled
sssd-autofs.service indirect
sssd.service disabled
sssd-autofs.socket disabled
Expected Output:
# systemctl list-unit-files | egrep -w "autofs.service|sssd.service"
autofs.service disabled
sssd.service disabled
解决方案
您可以使用
grep -E '^(sssd|autofs)\.service'
这里,
^
- 字符串的开始(sssd|autofs)
- 匹配两个子字符串中的任何一个的组\.service
- 一个.service
子串。
查看在线演示。
推荐阅读
- image - 在哪里可以找到包含大量高分辨率 CIE L*a*b* 图像的数据库?
- html - 如何在innerHtml中将自定义html标签显示为纯文本
- python - Python netCDF4 - 向现有文件添加一个新变量并改变形状
- java - JTextField 在鼠标悬停之前不可见
- css - 覆盖母版页,使内容为 100% 宽度
- google-apps-script - 尝试在 GAS doPOST 中使用开发模式
- passport.js - 如何封装 Koa-Passport?
- algorithm - 更好地理解 (log n) 时间复杂度
- c++ - C ++如何在不丢失内存的情况下删除节点?
- c++ - Mac OS X(CommandLineTools)上的c ++和g ++有什么区别?