Awk Utility example

Awk Utility example

Write a command using awk utility

awk ‘{ for (i=1; i<=NF; i++) if (length($i) > 5) print $i }’ F1

awk ‘{ for (i=1; i<=NF; i++) if (length($i) > 5 && $i ~ /^[A-Za-z]+$/) print $i }’ F1

awk ‘{ for (i=2; i<=NF; i+=2) print $i }’ F1

awk ‘{ count += gsub(/unix/, “”) } END { print count }’ F1

awk ‘{ count += gsub(/[AEIOUaeiou]/, “”) } END { print count }’ F1

awk ‘{

  for (i=1; i<=NF; i++) {

    word = $i

    if (word == reverse(word)) {

      print word

    }

  }

}

function reverse(s) {

  rev = “”

  for (i=length(s); i>0; i–) {

    rev = rev substr(s, i, 1)

  }

  return rev

}’ F1