I'm very pleased with the speed of using GNU parallel with splitting multi-GB CSV database export files into manageable chunks. However, the problem I'm having is that I'd like my output file names to be in the format some_table.csv.part_0000.csv
and start at zero (the import tool requires this). Getting "0001" was a challenge, but I managed to use printf to achieve this. I can't get the decrement to work though.
My Command:
FILE=some_table; parallel -v --joblog split.log --pipepart --recend '-- EOL\n' --block 25M "cat > $FILE.csv.part_$(printf "%04d"{#}).csv" :::: $FILE.csv
Doing things like expression expansion ($FILE.csv.part_$(({#}-1)).csv
) don't work because {#}
confuses the inner subshell. So does PART=$(({#}-1)); cat > $FILE.csv.part_$PART.csv
.
Any suggestions?