mercredi 12 octobre 2022

Generating 10 random numbers in a range in an awk script

So I'm trying to write an awk script that generates passwords given random names inputted from a .csv file. I'm aiming to do first 3 letters of last name, number of characters in the fourth field, then a random number between 1-200 after a space. So far I've got the letters and num of characters fine, but am having a hard time getting the syntax in my for loop to work for the random numbers. Here is an example of the input:

Danette,Suche,Female,"Kingfisher, malachite"
Corny,Chitty,Male,"Seal, southern elephant"

And desired output:

 Suc21 80
 Chi23 101

For 10 rows total. My code looks like this:

BEGIN{
FS=",";OFS=","
 }
{print substr($2,0,3)length($4)

 for(i=0;i<10;i++){
 echo $(( $RANDOM % 200 ))
}}

Then I've been running it like

awk -F"," -f script.awk file.csv

But it only shows the 3 characters and length of fourth field, no random numbers. If anyone's able to point out where I'm screwing up it would be much appreciated , thanks guys




Aucun commentaire:

Enregistrer un commentaire