Friday, July 15, 2022

command line / bash variable in awk command

 This is how we use a command line / bash variable (named num) in a awk command. We define an awk  variable 'var' with -v option. This also shows use of BEGIN block.

awk -F, -v var=$num 'BEGIN{srand(var)} {print $1","$2","rand()}' file_name 

No comments:

Post a Comment