December 6, 2005

Adding Random Data To Files

Category: VI — Raffael Marty @ 1:30 am

I find myself adding data to files that need to be randomized. Well, just call awk from within vi and use the rand() function

:%!awk ‘BEGIN {srand()}; {if (int(rand()*4)==2) {printf(“\%s,S\n”,$0)} else print $0;}’

Maybe even a bit more comfortable AND this only adds to the lines if they don’t use SA, S or F

:%!awk ‘BEGIN {srand()} \!/(SA|S|F)$/ {if (int(rand()*4)==2) {sub(/$/,”FA”);}};{print}’

No Comments »

No comments yet.

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> .