Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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.

share|improve this answer
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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .