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.?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI 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.
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