Remove first two and last two lines from a bash variable

I have a bash variable RESULT. I want to delete the first two and last two lines from this variable without writing it to a file. How do I do that?

1 answer

  • answered 2020-09-28 09:41 stas chern

    You can do that using head and tail commands as such:

    echo "$RESULT" | head -n -2 | tail -n +3