Integer division in awk

Use the int function to get the integer part of the result, truncated toward 0. This produces the nearest integer to the result, located between the result and 0. For example, int(3/2) is 1, int(-3/2) is -1. Source: The AWK Manual – Numeric Functions

Number of fields returned by awk

The NF variable is set to the total number of fields in the input record. So: echo “a b c d” | awk –field-separator=” ” “{ print NF }” will display 4 Note, however, that: echo -e “a b c d\na b” | awk –field-separator=” ” “{ print NF }” will display: 4 2 Hope … Read more

Finding gaps in sequential numbers

With awk : awk ‘$1!=p+1{print p+1″-“$1-1}{p=$1}’ file.txt explanations $1 is the first column from current input line p is the previous value of the last line so ($1!=p+1) is a condition : if $1 is different than previous value +1, then : this part is executed : {print p+1 “-” $1-1} : print previous value … Read more

Remove quotes in awk command

You can use gsub function: awk -F’,’ ‘{gsub(/”/, “”, $2); print “set”, $2, $3}’ testme.csv set 1211274723 “0” set 1211292921 “0” set 1211295793 “0” set 1211310146 “0” set 1211310310 “0” set 1211315271 “0” set 1211318203 “0” set 1211323658 “0” set 1211329224 “0” set 1211330064 “0”