I have written a bash script which is in following format:
#!/bin/bash
start=$(date +%s)
inFile="input.txt"
outFile="output.csv"
rm -f $inFile $outFile
while read line
do
-- Block of Commands
done < "$inFile"
end=$(date +%s)
runtime=$((end-start))
echo "Program has finished execution in $runtime seconds."
The while
loop will read from $inFile
, perform some activity on the line and dump the result in $outFile
.
As the $inFile
is 3500+ lines long, the script would take 6-7 hours for executing completely. In order to minimize this time, I am planning to use multi-threading or forking in this script. If I create 8 child processes, 8 lines from the $inFile
would be processed simultaneously.
How can this be done?