Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: split a file into number of file based on line count

by Utilitarian (Vicar)
on May 13, 2009 at 09:06 UTC ( [id://763703]=note: print w/replies, xml ) Need Help??


in reply to Re: split a file into number of file based on line count
in thread split a file into number of file based on line count

more specifically, to split into 5 ~equal files you can use the following construction in bash
split -l$(expr $(expr $(wc -l filename |cut -d\ -f1) / 5) + 1) filena +me

Replies are listed 'Best First'.
Re^3: split a file into number of file based on line count
by Bloodnok (Vicar) on May 13, 2009 at 10:02 UTC
    Why do all that when you can equally well use
    split -n 100 some_file
    ??

    See man split... (on some *NIXes, -l is used instead of -n to specify the line count)

    Update:

    Qualified the usage of the line count option

    A user level that continues to overstate my experience :-))
      Not general. See OP's ref to counting lines.
        Good point, well made ww :-D

        It's a classic case of me seeing what I wanted to - I saw ...split that file into 5 file each should contain 100 lines... and tho' I saw the subsequent narrative (fully defining the problem), I completely ignored it !!

        Glad it wasn't an exam :-D

        A user level that continues to overstate my experience :-))
Re^3: split a file into number of file based on line count
by JavaFan (Canon) on May 13, 2009 at 09:50 UTC
    That sounds like it can be golfed.
    split -l$((`cat filename|wc -l`/5+1)) filename

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://763703]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-25 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found