Shell matches the last two lines

I want to match the lines of a text file except the last two lines

cat xx
1
2
3
4
5
6
7
8

I want to match 1-6,

Jan.10,2022

head-n-2 / path/to/file


the answer upstairs is the standard solution, so let me provide another solution.

provides a built-in command mapfile in bash 4 + , as explained in the official bash manual:

Read lines from the standard input into the indexed array variable array, or from file descriptor fd if the-u option is supplied.
read a row of data from standard input into an indexed array, or provide the-u option to read row data from a file descriptor

here you can do something interesting with bash's redirection, which is to solve this problem with pure bash built-in commands.

   

head commands change with execution time, but built-in commands remain stable overall
Menu