如果第一个字段包含点,则提取一行

如果第一个字段包含点,则提取一行

实际数据是:

Dolibarr                      techpubl        http://techpublications.org/erp
tekstilworks.com              WordPress       tekstilw
wbq.dandydesigns.co         WordPress       cbeqte
WordPress                     cbeqte          http://wbq.dandydesigns.co
WordPress                     cbeqte          http://qbd.dandydesigns.co
WordPress                     cbeqte          http://uqdq.dandydesigns.co
dandydesigns.co               WordPress     cbeqte
stunlockers.info              WordPress         nmmuop

我想得到什么:

 tekstilworks.com              WordPress       tekstilw
 wbq.dandydesigns.co         WordPress       cbeqte
 dandydesigns.co               WordPress     cbeqte
 stunlockers.info              WordPress         nmmuop

答案1

使用 awk:

awk '$1 ~ /\./' input-file-here

awk 表达式中的句点必须使用反斜杠转义,这样它就不会被视为正则表达式语法。

答案2

使用grep来匹配.第一个字段:

grep '^[^[:blank:]]*\.' file.txt

例子:

$ cat file.txt
Dolibarr                      techpubl        http://techpublications.org/erp
tekstilworks.com              WordPress       tekstilw
wbq.dandydesigns.co         WordPress       cbeqte
WordPress                     cbeqte          http://wbq.dandydesigns.co
WordPress                     cbeqte          http://qbd.dandydesigns.co
WordPress                     cbeqte          http://uqdq.dandydesigns.co
dandydesigns.co               WordPress     cbeqte
stunlockers.info              WordPress         nmmuop

$ grep '^[^[:blank:]]*\.' file.txt
tekstilworks.com              WordPress       tekstilw
wbq.dandydesigns.co         WordPress       cbeqte
dandydesigns.co               WordPress     cbeqte
stunlockers.info              WordPress         nmmuop

答案3

只是为了好玩,狂欢

(set -f; while IFS= read -r line; do set -- $line; [[ $1 == *.* ]] && echo "$line"; done) <filename

相关内容