Join joins all the lines in the pipe's contents into a single space-separated string, which will always end with a newline.
()
| 696 | // Join joins all the lines in the pipe's contents into a single |
| 697 | // space-separated string, which will always end with a newline. |
| 698 | func (p *Pipe) Join() *Pipe { |
| 699 | return p.Filter(func(r io.Reader, w io.Writer) error { |
| 700 | scanner := newScanner(r) |
| 701 | first := true |
| 702 | for scanner.Scan() { |
| 703 | if !first { |
| 704 | fmt.Fprint(w, " ") |
| 705 | } |
| 706 | line := scanner.Text() |
| 707 | fmt.Fprint(w, line) |
| 708 | first = false |
| 709 | } |
| 710 | fmt.Fprintln(w) |
| 711 | return scanner.Err() |
| 712 | }) |
| 713 | } |
| 714 | |
| 715 | // JQ executes query on the pipe's contents (presumed to be valid JSON or |
| 716 | // [JSONLines] data), applying the query to each newline-delimited input value |