Split "-n" unknown option

Hello,

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.

Please comment.

cat input
@a1101:00000630
TTTTTCTGATAAGCTGGTTCTCACTTCTGTTACTCCATCTTCTTCGGCACC
+
AAAAAFFD3DDDFGFF1FGGDFDAGFHHBGHCEGDG11BA2221D00AAEF
@a1101:00000924
GGAAGAAAAGGACTCTGACAGCATGGAGGACACGGGCCCTTATTCCATCAA
+
111>11CBFF?C1GFGCGFGFG0BFC1BAEECGC0EE//AA1AADBFGFDD
split -n r/1/4 input
split: invalid option -- 'n'
Try `split --help' for more information.



My split version - split (GNU coreutils) 8.4

Thank You

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).

1 Like

man split for split (GNU coreutils) 8.25 says

What does your man split tell you about the -n option?

Hi.

I'd guess that an alias or command named split occurs in the PATH before the system split ,

What are the results of (with bash):

command -V split
which split

If it's not:

$ which split
/usr/bin/split

$ command -V split
split is /usr/bin/split

then you're not getting the GNU split .

The version of split on my system is: split (GNU coreutils) 8.23

Best wishes ... cheers, drl

Thank you all.

The developer replied back with an alternate solution.

In 8.4 version of split, there is no option of -n.

Thanks

So, just upgrade to latest coreutils version.

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.

1 Like