unix - Delete all lines after a string but the last few -


i have file contains lines , numbers. want delete lines after particular string, let string 'angles'. want delete lines after angles, can using sed command follows:

sed -n '/angles/q;p' input file 

my question is, want delete lines after angles want retain last 4 lines? how can in sed?

the following should work you:

tac inputfile | sed '5,/angles/d' | tac 

explanation: reverse file, keep first 4 lines , delete until desired pattern encounterd. reverse result.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -