I am trying to run a third party script. I have no idea what is the purpose of this below split command. But it throws an error saying invalid option -n.
Perhaps we would have a better chance of helping you if you told us what operating system successfully runs this third party script. And, it would probably help even more if you told us what output you hope to produce from the sample input file you provided.
According to the standards, the split -n option takes a numeric option-argument that specifies the number of digits to be placed in the names of the output files produced. The option-argument your script is providing ( r/1/5 ) does not appear to be a numeric value to me, so it is no wonder that you are getting a diagnostic message (although that diagnostic is not what I would have expected).
What -n r/K/N does is print every K/Nth line. If K = 1 and N =2, you the first line, then every 2nd line after to the end of the stream. With K = 1 and N = 4, you get the first line, then every 4th line after. This is easy enough to replicate with any of the other tools. I think sed would be the best, but my sed-foo is weak, so I'll use awk.
split() {
if [ "$1" = "-n" -a "${2:0:1}" = "r" ]; then
local k="${2:2:1}"
local n="${2##*/}"
shift; shift;
if [ "${1#-}" != "$1" ] ; then
echo >&2 "Warning: additional options to split need to be handled by this function"
fi
awk -v k=$k -v n=$n '(NR%n)==(k%n)' "$@"
else
command split "$@"
fi
}
I tested the above code using a 3-way split against a large input file and compared it to GNU split v 8.21.
If they pass other options to split, you'll have to implement those or work around them.