Posted By

http on 02/12/16


random awk word

Versions (?)

Random word from a text file, excluding short non alphabetic charaters

 / Published in: Awk

Allows to take any text file containing numbers and non alphabetic characters and extract a random word from it

  1. gawk 'BEGIN {srand(systime() + PROCINFO["pid"])}
  2. {gsub(/[^[:alpha:]]/," ")
  3. for (i=1;i<=NF;i++) if (length($i)>3) a[++j]=$i}
  4. END{print a[int(j*rand())]}' place-file-here

Report this snippet  

You need to login to post a comment.