Delete all lines after a specific line ?

Hello.
My file is like this:
a
b
c
d
e
f
g
h
i
I want to delete all lines after the 3rd line, means after the "c". Is there any way to do this? The lines differ between them and the lines I want to delete does not have a specific word, or the lines I want to keep (a,b,c) does not have a common word. So, I basicly need to delete all the lines from this file except the 3 first. :b: I bet you got it

sed '4,$d' filename
1 Like

Have a read of this:

Man Page for head (POSIX Section 1) - The UNIX and Linux Forums

1 Like
head -3 filename
1 Like

Thank you both.

---------- Post updated at 12:41 PM ---------- Previous update was at 12:41 PM ----------

EDIT: Thank you all.