I want to split files which are >500kb. For this first I use find to list all such files find . -maxdepth 1 -name '*.log' -size +500k
that returns "./filename" and then I write another command to split file according to my requirement split -b 500k -d -a 4 filename filename.
here filename is the output of first command. Now can someone help me to combine both of them such that the output of first is input of second command.
Asked
Active
Viewed 146 times
1

fedorqui
- 275,237
- 103
- 548
- 598

Piyush Singh
- 533
- 5
- 17
2 Answers
2
How about a one liner?
find . -maxdepth 1 -name '*' -size +500k -exec 'split' '-b' '500k' '-d' '-a' '4' '{}' '{}' ';'

e4c5
- 52,766
- 11
- 101
- 134
-
1Glad to have been of help – e4c5 Aug 08 '16 at 10:08
1
You can use a process substitution for this:
while IFS= read file
do
split -b 500k -d -a 4 "$file" "$file"
done < <(find . -maxdepth 1 -name '*.log' -size +500k)
That is: the while
loop gets fed by the find
output.

fedorqui
- 275,237
- 103
- 548
- 598