场景:

*   soft 	 nofile 630000
*	 hard   nofile 654300

grep 匹配如上文本,由于最后一列数字是可变的,并且每列之间可能存在任意个空格或制表符

grep   -E  '^\*[[:space:]]+soft[[:space:]]+nofile|^\*[[:space:]]+hard[[:space:]]+nofile'  /etc/security/limits.conf

将匹配的结果sed 替换最后一列数字

sed -n 's/\*[[:space:]]\+soft[[:space:]]\+nofile.*/\* soft nofile 654350/p;s/\*[[:space:]]\+hard[[:space:]]\+nofile.*/\* hard nofile 654350/p' /etc/security/limits.conf

区别,在匹配任意个数空格或制表符时,grep 的'+' 不需要转义,sed 需要转义

相关文章:

  • 2021-11-27
  • 2022-12-23
  • 2021-04-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2021-07-09
相关资源
相似解决方案