Search code examples
linuxubuntupipetailunix-head

How to print lines between 2 values using tail & head and pipe?


For example:how can I print specific lines of a .txt file between line 5 and line 8 using only tail and head


Solution

  • Copied from here

    infile.txt contains a numerical value on each line.

    ➜   X=3
    ➜   Y=10
    ➜   < infile.txt tail -n +"$X" | head -n "$((Y - X))"
    3
    4
    5
    6
    7
    8
    9
    ➜