shell中sed和grep匹配任意空格或制表符的區別


場景:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM