LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-27-2005, 12:23 PM   #1
tebucky
Member
 
Registered: Mar 2004
Posts: 89

Rep: Reputation: 15
Random Name Shell Script


Hello,

I am very new to shell scripting and looking for a little help. Could someone show me the contents of a script that would read a file with a list of first and last names and randomly select that name out of the aforesaid list? As you can tell this is for a random raffle.

TIA!
 
Old 04-27-2005, 12:38 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 68
Assuming the names are in names.txt:
Code:
#!/bin/bash

total=`wc -l names.txt | awk {'print $1'}`

rand=$(((($RANDOM*$total)/32767)+1))

echo Winner is person $rand

head -n $rand names.txt | tail -n 1
 
Old 04-27-2005, 12:47 PM   #3
tebucky
Member
 
Registered: Mar 2004
Posts: 89

Original Poster
Rep: Reputation: 15
perfect!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script Random Variable Daniel Programming 14 12-03-2007 05:00 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Shell scripting - Random numbers within a range felixc Linux - Newbie 2 10-09-2005 05:41 PM
Creating random numbers from shell with /dev/random khermans Linux - General 1 07-13-2004 12:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration