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


/ Published in: Awk
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.