2

How can I print from the fourth to the second last line using sed command?

1
  • "fourth" -- the fourth line (from the top) or the fourth-last line? Commented Mar 12, 2020 at 13:56

2 Answers 2

2
sed -e '4,$!d' -e '$d'

Ex.

$ printf 'Line %d\n' {1..10} | sed -e '4,$!d' -e '$d'
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
2

Try this,

sed -e '1,3d;$d' file
  • 1,3d to delete first 3 lines.
  • $d to delete last line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .