Thursday, 7 November 2013

awk script to count lines without vowels in a file.

[singh@00-13-02-56-15-7c programs]$ vi test1

engineering
data
and
lab
workshop
programming
rdx
bpb
hp

[singh@00-13-02-56-15-7c programs]$ vi raj11.sh

#!/bin/bash
echo "Enter file name"
read file
awk '$0!~/[aeiou]/{ count++ }
END{print "The number of lines that does not contain vowels are: ",count}' $file


Output :

[singh@00-13-02-56-15-7c programs]$ sh raj11.sh
Enter file name
test1
The number of lines that does not contain vowels are:  3

 

6 comments:

  1. rather the correct solution would be:

    echo "Enter file name"
    read f
    count=0
    awk '$0!~/[aeiou]/{ count++ }
    END{printf "The number of lines that does not contain vowels are: %d\n",count}' $f

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete