0

I understand that final result of

sed -e :a -e '$d;N;2,5ba' -e 'P;D' file

I don't understand what :a, ba mean. Also I get confused why -e is specified 3 times?

jaypal singh
  • 74,723
  • 23
  • 102
  • 147

1 Answers1

1

-e specifies a sed script of which there are 3.

:a 

is a label for use with b and t commands.

$d;N;2,5ba

means match the last line and delete. The next input line is appended into pattern space. For lines 2, 5 we'll branch to label :a.

Last script prints pattern space up to the first newline, and deletes up to the first newline in the pattern space.

nanofarad
  • 40,330
  • 4
  • 86
  • 117
  • So let me get it straight: -e:a is label "declaration", then sed goes to delete last line. But how does it count backwards from 2 to 5 from the end. Isn't count goes from top? Thank you. – user2616821 Jul 25 '13 at 02:17
  • Ok! I read http://stackoverflow.com/questions/12833714/the-concept-of-hold-space-and-pattern-space-in-sed and I think I got it. Thank you very much for your answer, hexafraction – user2616821 Jul 25 '13 at 02:29