[ Naming files after splitting them with split command within a pipeline ]
I've been recently dealing with splitting large files and processing them further.
My current pipe is very simple>
find . -type f -size +100M | split -b 100M
But what this does is not exactly what I'm after. I would like splitted files named similarly to input files to split function, for example> inputs of find are>
file1
file2
file3
I would like output in the lines of for example
file101 file102 ...
file201 file202 ...
file301 file302 ...
I tried with >
split -b 100M -d $(find . -type f -size +1000M) $(find . -type f -size +1000M)
but it doesn't work as I wish, it throws error!
Thanks.
Answer 1
split
doesn't read the filenames from standard input. You have to give the filename as an argument. You can do that with the -exec
option to find
. Use the {}
placeholder to substitute the filename for both the input file and the output prefix arguments.
find . -type f -size +100M -exec split -b 100M -d {} {} \;