Matthew Rathbone
Matthew Rathbone

Reputation: 8269

How can I change where unix pipe sends its results for the split command?

Basically I'm doing this:

export_something | split -b 1000

which splits the results of the export into files names xaa, xab, xac all 1000 bytes each

but I want my output from split to go into files with a specific-prefix. Ordinarily I'd just do this:

split -b <file> <prefix>

but there's no flag for prefix when you're piping to it. What I'm looking for is a way to do this:

export_something | split -b 1000 <output-from-pipe> <prefix>

Is that possible?

Upvotes: 6

Views: 4298

Answers (4)

Blender
Blender

Reputation: 298156

You could use an inline expression (or whatever it's called, I can never remember) to export the data directly into the function as a string:

 split -b 1000 "`export_something`" <prefix>

Hope this works.

Upvotes: 0

Dan D.
Dan D.

Reputation: 74645

use - as input as split --help says

Upvotes: 1

The Archetypal Paul
The Archetypal Paul

Reputation: 41749

Use - for input

Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...;

default size is 1000 lines, and default PREFIX is `x'.

With no INPUT, or when INPUT is -, read standard input.

export_something | split -b 1000 - <prefix>

Upvotes: 3

dennycrane
dennycrane

Reputation: 2331

Yes, - is commonly used to denote stdin or stdout, whichever makes more sense. In your example

export_something | split -b 1000 - <prefix>

Upvotes: 13

Related Questions