代码之家  ›  专栏  ›  技术社区  ›  Yasir NL

我想从文件中恢复特定的模式

  •  -1
  • Yasir NL  · 技术社区  · 7 年前

    文件大洲

    Yasir.txt
    Yasir1.txt
    <txt>
    Nothing 
    </txt>
    

    如果我使用grep命令

    grep ".txt" file
    

    我得到

    Yasir.txt
    Yasir1.txt
    <txt>
    </txt>
    

    我在期待

    Yasir.txt
    Yasir1.txt
    

    请帮帮我

    3 回复  |  直到 7 年前
        1
  •  3
  •   DavidP    7 年前

    你需要使用

    grep "\.txt" file
    

    当做

        2
  •  1
  •   ashish_k    7 年前

    使用A sed 一班轮:

    sed -n '/\.txt/p' file_name
    

    我认为使用davidp的答案似乎更方便 grep :)

        3
  •  0
  •   Geno Chen    7 年前

    尝试使用grep的perl正则表达式?

    grep -P ".txt$"