0

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
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Alfe
  • 56,346
  • 20
  • 107
  • 159
  • How come you got 22k rep score and still did not learn the rules here? – Marcin Orlowski Jul 27 '17 at 15:51
  • Do you ask that because you think this question is too simple to answer and thus is way below your level? – Alfe Jul 27 '17 at 15:52
  • 1
    I ask because I wonder how one can earn 22k rep and still not understand what questions are on-topic here and, how it should be asked. I also wonder how come you failed to search for the solution yourself, and the only answer I can come with is that you did not even try. The only thing you did was to post your "question" with tons of unrelated tags. Good job. – Marcin Orlowski Jul 27 '17 at 16:00
  • @MarcinOrlowski No, you are wrong. I searched for several minutes and found a bunch of kind-of solutions but they always contained something which made them unusable for me (like a C# solution, or in Python, or stripping parts of lines instead of the last line). Obviously my search keywords weren't good enough. But in this situation it makes sense to ask again and get closed as duplicate because that helps other searchers with the same search words to find the answer. – Alfe Jul 27 '17 at 16:04

1 Answers1

1

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

$ sed \$d file
John Goofy
  • 1,330
  • 1
  • 10
  • 20