MCPcopy
hub / github.com/bitfield/script / Last

Method Last

script.go:765–786  ·  view source on GitHub ↗

Last produces only the last n lines of the pipe's contents, or all the lines if there are less than n. If n is zero or negative, there is no output at all.

(n int)

Source from the content-addressed store, hash-verified

763// if there are less than n. If n is zero or negative, there is no output at
764// all.
765func (p *Pipe) Last(n int) *Pipe {
766 if p.Error() != nil {
767 return p
768 }
769 if n <= 0 {
770 return NewPipe()
771 }
772 return p.Filter(func(r io.Reader, w io.Writer) error {
773 scanner := newScanner(r)
774 input := ring.New(n)
775 for scanner.Scan() {
776 input.Value = scanner.Text()
777 input = input.Next()
778 }
779 input.Do(func(p interface{}) {
780 if p != nil {
781 fmt.Fprintln(w, p)
782 }
783 })
784 return scanner.Err()
785 })
786}
787
788// Match produces only the input lines that contain the string s.
789func (p *Pipe) Match(s string) *Pipe {

Calls 5

ErrorMethod · 0.95
FilterMethod · 0.95
NewPipeFunction · 0.85
newScannerFunction · 0.85
DoMethod · 0.80