awk: send results to file named using bash variable -
i have bash variable log_filename
stores name of log file. want launch iostat -xnmp
, fields 9, 10 , 11 of every record of every iteration matching pattern stored in bash variable device
. number of iterations stored in time
bash var. trying is:
iostat -xnmp 5 $time | awk -v log=$log_filename "/$device/" '{print $9" "$10" "$11}' input >> $log
and lots of variations environ
, others...but still couldn't figure out wrong. getting syntax error of time. there no particular requirements yet, solution suitable.
my take on (one liners okay easier humans read separate lines):
iostat -xnmp $time | awk -v dev=$device 'index($0,dev)>0 {print $9,$10,$11}' >> $log
you read stdin. index($0,dev)>0
used because think have 1 disk device in mind. index($0,dev)>0
can shortened index($0,dev)
less clarity folks learning awk.
Comments
Post a Comment