Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding random numbers to a file of Words

Status
Not open for further replies.

csunix

Programmer
Mar 23, 2004
129
GB
Does anybody have a script that can be ran against a file that has a list of dictionary words that will add numbers onto the end of these words

eg Invent to become Invent12
Friday to become Friday94


Any suggestions would be appreciated.

Thanks, CS
 
In perl:
Code:
#!/usr/bin/perl -w
while(<>) {
    s/(\w+)/$1 . int(rand(100))/eg;
    print;
}
Cheers, Neil
 
Or using awk, assuming 1 word per line

BEGIN {srand()}
{ print $1 int(rand()*100) }

CaKiwi
 
Or in Kornshell or Bash, again assuming 1 word per line:

Code:
while read word
do
echo "${word}$((${RANDOM} % 100))"
done < inwords.txt > outwords.txt

I sure hope you're not generating passwords this way.

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top