#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    14
    Rep Power
    0

    Bash random numbers


    Hi

    I would like to write a BASH function for .bashrc that would reduce the datafile content for a certain amount in a random way. For example, if the file has a 100000 lines I would like to create a new one keeping only 10% of lines but chosen randomly. Could someone help me on this? how to generate random numbers that could be used in BASH

    I do not mind combinations with grep, awk ect ... just to be usable from .bashrc

    thanks
    oliver
  2. #2
  3. No Profile Picture
    Google's No1 Supporter!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2007
    Location
    The Crisp Packet!
    Posts
    603
    Rep Power
    152
    You're in the wrong place. You need to be in either "linux help" or "unix help". You'll get more help over there
    *watches mod move it*
    Last edited by xnemesis64; June 4th, 2007 at 07:04 PM. Reason: You aren't in the "wrong" place, there are just some better ones for your problem =)
    Did this post help? Please Click The Next To My Post
    Need help? Did you try Google?
  4. #3
  5. No Profile Picture
    Google's No1 Supporter!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2007
    Location
    The Crisp Packet!
    Posts
    603
    Rep Power
    152
    To save a further edit, I'll reply again.

    Dependent on what OS exactly you are using take a look at /dev/random

    You should be able to:
    Code:
    cat $var >/dev/urandom
    And a random number will be in $var for you now.

    Hope this helps
    Did this post help? Please Click The Next To My Post
    Need help? Did you try Google?

IMN logo majestic logo threadwatch logo seochat tools logo