Search code examples
shelltruncatehead

Strip last line in shell


How can I strip the last line off a text file with Unix tools? Action can take place in place, so probably a version of truncate would be appreciated.

I guess there should be a solution using grep, sed, or head or similar tools, but I couldn't figure out a concise version.

Input:

one
two
three

Output:

one
two

Solution

  • sed is your friend. This prints everything but not the last line of a given file.

    $ sed \$d file