March 2018
Beginner to intermediate
416 pages
9h 24m
English
The unquoted caret ^ matches the string at the beginning of line. The ^ is only the anchor if it is the first character in the regular expression. For example, we use the /^J/ regular expression to match all the lines that begin with J. It will print the employee information of those whose first name begins with the J character in the employee database:
$ awk '/^J/{ print }' emp.dat
The output on execution of the preceding code is as follows:
Jack Singh 9857532312 jack@gmail.com M hr 2000Jane Kaur 9837432312 jane@gmail.com F hr 1800Julie Kapur 8826234556 julie@yahoo.com F Ops 2500John Kapur 9911556789 john@gmail.com M hr 2200
We can also use the anchor, ^ (caret), with the string match operator (~)
Read now
Unlock full access