Split "-n" unknown option

Login or Register to Reply

Thread Tools Search this Thread
# 1  
Old 09-28-2016
Split "-n" unknown option


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

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

Last edited by jacobs.smith; 09-28-2016 at 09:16 AM..
# 2  
Old 09-28-2016
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).
This User Gave Thanks to Don Cragun For This Post:
jacobs.smith (09-28-2016)
# 3  
Old 09-28-2016
man split for split (GNU coreutils) 8.25 says

-n, --number=CHUNKS
generate CHUNKS output files; see explanation below

CHUNKS may be:
N split into N files based on size of input
r/K/N likewise but only output Kth of N to stdout
What does your man split tell you about the -n option?
# 4  
Old 09-28-2016

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

$ 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

Last edited by drl; 09-28-2016 at 04:38 PM..
# 6  
Old 09-29-2016
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"
   awk -v k=$k -v n=$n '(NR%n)==(k%n)' "$@"
   command split "$@"

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.
This User Gave Thanks to otheus For This Post:
drl (09-30-2016)
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9" jcdole Shell Programming and Scripting 1 01-19-2019 05:37 AM
Using "mailx" command to read "to" and "cc" email addreses from input file asjaiswal UNIX for Dummies Questions & Answers 2 10-11-2014 09:32 PM
Unknown Disks "offline or reservation conflict" MobileGSP Solaris 7 11-17-2012 04:57 AM
Sendmail saying "user unknown" after setting up MX Rohit Bhanot Red Hat 2 07-31-2012 11:15 PM
What is the meaning of "-s" option in "if" statement? rymnd_12345 UNIX for Dummies Questions & Answers 7 05-03-2012 12:22 PM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
CRON JOB SCHEDULER throwing "option not allowed error" trueharsh UNIX for Dummies Questions & Answers 3 07-23-2010 04:23 PM
if returns "unknown test operator" 22blaze Shell Programming and Scripting 3 04-24-2009 07:07 PM
read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell wiseguy Shell Programming and Scripting 9 01-28-2009 12:20 PM
HP Tape Driver "Unknown Density" stufftiger HP-UX 2 07-27-2008 12:29 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 12:52 AM
unknown error message "sh: No: not found" cindytucci UNIX for Advanced & Expert Users 2 07-26-2005 12:44 PM