Using AWK to filter out column with numerical ranges Using AWK to filter out column with numerical ranges bash bash

Using AWK to filter out column with numerical ranges


awk '{ if ($4 >= 1 && $4 <= 10) print $1 }' sample.txt


awk '$4 ~ /^[1-9]$|^10$/{print $1}' sample.txt

output:

sample1sample2

explanation:

  • ^[1-9]$ --> $4 must be a single digit from 1 to 9
  • | (the pipe) --> or
  • ^10$ --> $4 must be the number 10


awk -F ':' '$4 >= 1 && $4 <= 10{print $1}'