bengreen.eu Circle Device

 

Quick Reference

awk

AWK to Extract Section of a File

Extract a section of a file based on a start and end pattern, and do a little arithmetic:

BEGIN{FS=",";OFS=",";found=0;reading_no=0}
/2019-01-11 10:02:2/{found=1;depth=50;wt=5}
/2019-01-11 10:04:0/{found=0}
/2019-01-11 10:04:1/{found=1;depth=100}
/2019-01-11 10:06:0/{found=0}
{if(found){d_diff_a=depth-$9;d_diff_b=depth-(($10+400)/4);print $0","depth","d_diff_a","d_diff_b","reading_no","wt;reading_no++}}

FS is field separator OFS is other field separator.

$10 refers to the 10th field in this file (in this example like the 10th column in a CSV).

Using AWK to Update DNS Records

Quick Links: Techie Stuff | General | Personal | Quick Reference