fsckzy
V2EX  ›  问与答

shell 如何匹配最后两行?

  •  
  •   fsckzy · Dec 4, 2018 · 2637 views
    This topic created in 2895 days ago, the information mentioned may be changed or developed.

    文件内容如下:

    e0ebd07d refs/tags/release-1
    a9afb2b5 refs/tags/release-2
    7de1982d refs/tags/release-3
    e0ebd07d refs/tags/release-4
    e0ebd07d refs/tags/release-5
    a9afb2b5 refs/tags/release-6
    7de1982d refs/tags/release-7
    e0ebd07d refs/tags/release-8
    

    我想匹配除了最后两行的其他行?

    5 replies  •  2018-12-04 14:33:26 +08:00
    realityone
    realityone
    Dec 4, 2018
    1
    不知道你想要表达什么。

    标题:gtail -n -2
    正文:ghead -n -2

    是 GNU Coreutils 的 head 和 tail
    pkookp8
    pkookp8
    Dec 4, 2018 via Android
    2
    grep -vE "release-[78]"
    fsckzy
    fsckzy
    OP
    Dec 4, 2018
    3
    @realityone
    @pkookp8 我是想匹配一个文本文件除了最后两行的其他行。
    zbinlin
    zbinlin
    Dec 4, 2018
    4
    head -n-2 <filename>
    fsckzy
    fsckzy
    OP
    Dec 4, 2018
    5
    @zbinlin 谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   822 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:25 · PVG 02:25 · LAX 10:25 · JFK 13:25
    ♥ Do have faith in what you're doing.