I want to split a file into multiple files with at most 25 lines each.

I'm using this:

split -l 25 /etc/adduser.conf > /home/ubuntu/PL/trab3/rc_

But I do not get the files I expect.

How can I get files with filenames like rc_01, rc_02, etc.?


Redirection (the > sign) is handled by the shell, and it can only output to a single file, the file you name. Omit the >, so that /home/ubuntu/PL/trab3/rc_ is passed to split as a command line argument, so that it can use that as its output prefix.

  • 9
    PS: Instead of just saying that something "doesn't work," it's better to say what happens... what error message(s) you get, what happens that you weren't expecting, what doesn't happen that you were expecting, etc. – coneslayer Mar 26 '10 at 18:19
  • split --help would help also – laconbass Apr 30 '15 at 23:05

Split doesn't support suffix for output file names. AFAIK it supports only prefix. For text files, you could try awk:

awk 'NR%25==1 { i+=1;file = "/home/ubuntu/PL/trab3/rc" "_" sprintf("%02d", i) } { print > file }' /etc/adduser.conf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.