Paul Sun Paul Sun - 7 months ago 10
Bash Question

Is there a way to use pipe to transfer only one parameter to the script?

This command can split a large_file to several files:

split -l 200 large_file prefix


Each file have 200 lines and named after prefix.

How to use pipe to transfer the parameters to split?

cat large_file | split -l 200 prefix # this command doesn't work.

Answer
cat large_file | split -l 200 - prefix # - means stdin

This is pretty conventional in many Unix programs: - means stdin (or stdout if it were an output file). So much so that some programs don't even document the behavior, though man split does:

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