grep在精确搜索中不考虑点

有可能只grep完全匹配吗?

我的档案

# cat tlds.csv 
159,.COM,com.csv
862,.UK.COM,uk.com.csv
866,.US.COM,us.com.csv

我在终端中的命令

# cat tlds.csv | grep -i -w  'com.csv'
159,.COM,com.csv
862,.UK.COM,uk.com.csv
866,.US.COM,us.com.csv

所需的输出 ** 159,.COM,com.csv **

I need only com.csv no other result. any way to get this done ?

评论
  • jquia
    jquia 回复

    您可以使用正则表达式:

    cat tlds.csv | grep -E ',com.csv$'
    

    In this way, you tell grep that you want only those lines that have a , before com.csv, and nothing more after com.csv.

    您也可以使用

    cat tlds.csv | grep -E '[^.]com.csv$'
    

    to tell grep that before com.csv it's okay any char except for .. Anyway, if I can add a suggestion I wouldn't use cat. grep can take your file as an argument, int this way:

    grep -E '[^.]com.csv$' tlds.csv