I have a file contining some no of lines. I want split file into n no.of files with particular names. It doesn't matter how many line present in each file. I just want particular no.of files (say 5). here the problem is the no of lines in the original file keep on changing. So I need to calculate no of lines then just split the files into 5 parts. If possible we have to send each of them into different directories.
Right-click the file and select the Split operation from the program's context menu. This opens a new configuration window where you need to specify the destination for the split files and the maximum size of each volume. You can select one of the pre-configured values or enter your own into the form directly.
To split a file equally into two files, we use the '-n' option. By specifying '-n 2' the file is split equally into two files.
In bash, you can use the split
command to split it based on number of lines desired. You can use wc
command to figure out how many lines are desired. Here's wc
combined with with split
into one line.
For example, to split onepiece.log
into 5 parts
split -l$((`wc -l < onepiece.log`/5)) onepiece.log onepiece.split.log -da 4
This will create files like onepiece.split.log0000
...
Note: bash division rounds down, so if there is a remainder there will be a 6th part file.
On linux, there is a split
command,
split --lines=1m /path/to/large/file /path/to/output/file/prefix
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is 'x'. With no INPUT, or when INPUT is -, read standard input.
...
-l, --lines=NUMBER put NUMBER lines per output file
...
You would have to calculate the actual size of the splits beforehand, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With