場景:
* 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 需要轉義