2018年9月20日 星期四

[linux] 怎麼使用 grep 列出符合長度匹配

怎麼使用 grep 列出符合長度匹配
可以使用grep 加上 line regex 來 列出符合長度的部份
列出字典裡面的<5 長度的字
grep -x '.\{1,5\}' /usr/share/dict/american-english 
找出長度是5的字
grep -x '.\{5,5\}' /usr/share/dict/american-english 

       -x, --line-regexp
              Select only those matches that exactly match the whole line.  For a regular expression
              pattern, this is like parenthesizing the pattern and then surrounding it with ^ and $.

沒有留言:

張貼留言