Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
scripting:nonportable [2019/08/30 16:25]
ersen use a for loop instead of while for gawk command
scripting:nonportable [2019/08/30 16:30] (current)
ersen use a for loop instead of while for mawk and nawk command
Line 87: Line 87:
  
 # '​nawk'​ and '​mawk'​ does the same, but needs a seed to be provided for its rand() function. ​ In this example we use $(date) # '​nawk'​ and '​mawk'​ does the same, but needs a seed to be provided for its rand() function. ​ In this example we use $(date)
-randpm=$(mawk -v min=1 -v max=500 -v nNum=10 -v seed="​$(date +%Y%M%d%H%M%S)"​ 'BEGIN {srand(seed);​ i = 0; while (i < nNum) { print int(min+rand()*(max-min)); ++i} }')+randpm=$(mawk -v min=1 -v max=500 -v nNum=10 -v seed="​$(date +%Y%M%d%H%M%S)"​ 'BEGIN { srand(seed); ​for (i = 0; i < nNum; ++i) {print int(min + rand() * (max - min)} }')
 </​code>​ </​code>​
 //Yes, I'm not an ''​awk''​ expert, so please correct it, rather than complaining about possible stupid code!// //Yes, I'm not an ''​awk''​ expert, so please correct it, rather than complaining about possible stupid code!//
  • scripting/nonportable.txt
  • Last modified: 2019/08/30 16:30
  • by ersen