Mani G Mani G - 1 month ago 5x
Bash Question

Regular expression which is suitable for use with egrep

Need to print Lines that contain nothing but a single occurrence of laughter, where laughter is de fined as a string of the form Hahahahahahahahahahahahahaha!, with arbitrarily many ha's.

What I have is

egrep "^Ha.*[ha*][!$]" myfile.txt

and it prints

Hahahahahahahahahahahahahaha! nklddln

and myfile.txt contains

So How is going on Man.
I am now just trying to test the stuff with Ubuntu
Digit in the line 1
Regular<title> expression</title> stuff must be working
alright just testing
liNUx.student.cs.uwaterlOO.Ca so the things
We need to</title> have more thn ten<title> lines that have more tha twenty characters
So, the assignment needs to be done very quickly
This cs247 line contains the course code cs246
The course code cs246 is in the cs247 line
All these lines in this text file are for testing only
We need to<title></title> thouroughly check the cs246 assignment
heheheheehe man this work will take some time
you have to be quick as we need to get it done before deadline
Okey kaka g whats the situation
Man How are you?
course code is CS246
course CS246
ghjf akf Hahahahahahahahahahahahahaha!
dhgD Hahahahahahahahahahahahahaha! jwef
Hahahahahahahahahahahahahaha! nklddln
hufwf Hahahahahahahahahahahahahaha!
course cs246

I do not want the second line to be printed as it contains an extra word. Use of egrep is must.


You need to use anchor $ after ! for precise matching:

egrep '^Ha(ha)+!$' file