Using and passing arguments to shuf within awk

Hello all,

I would like to output a random number within a range for every line using awk and shuf. I think I'm almost there, but I don't know how to pass arguments to shuf within my awk script:

Input

1 12190 12227
1 12595 12721
1 13403 13639
1 14362 14829
1 14970 15038

awk:

awk '{ a = (shuf -i $2"-"$3 -n 1)}{print $1,a}' Input

Desired Output (with second column being a random number between field 2 and 3 of input file):

1 12211
1 12659
1 13411
1 14705
1 15021

Al I get so far is

1 012190-122271
1 012595-127211
1 013403-136391
1 014362-148291
1 014970-150381

Any help would be greatly appreciated!

Seb

Perl, ok?

perl -lane 'print "$F[0] ", int(rand($F[2]-$F[1])) + $F[1]' file
1 Like

I'm not used to perl, but this works nicely. Thanks!