Victor
Victor

Reputation: 39

How to use linux to split a file into several files with different lines?

I want to use linux command lines to split a file into several files which will have different lines. How can I make it?

E.g. Suppose a file with 1000 lines, how can I split first 600 lines into file1, and remaining 400 lines into file2? I know split can split a big file by same lines, but I don't know wheather I can still use it here.

I'll highly appreciated If anyone could help me. Thanks!!

Upvotes: 0

Views: 110

Answers (1)

Adrian
Adrian

Reputation: 2354

For your example if you use

split FILE --lines=600

The last 400 lines will end up in the last fragment.

If you want to do arbitrary splits I'd suggest combining head and tail.

# e.g. get the 300 lines following line 250
tail  -n +250  FILE | head -n 300

Upvotes: 1

Related Questions