top of page
Search

Using Grep

  • Writer: Oliver Santana
    Oliver Santana
  • Oct 2, 2019
  • 1 min read

Updated: Dec 9, 2019


Use the file provided called datebook and test your knowledge of the linux grep command by reviewing the commands below:


1.Print all lines containing the string San .


grep 'San' datebook or you can use cat datebook | grep ‘San’ //grep looks for words in quotes


2.Print all lines where the person's first name starts with J .


grep ^J datebook //The '^' means look at the start


3.Print all lines ending in 700 .


grep -E ‘700\b’ datebook // The \b looks for the end of the line


4.Print all lines that don't contain 834 .


grep -w “834” datebook


5.Print all lines where birthdays are in December .


grep “12/[0-9]/[0-9]\{2\}” datebook


6.Print all lines where the phone number is in the 408 area code.


grep “408-[0-9]\{3\}-[0-9]\{4\}” datebook


7.Print all lines containing an uppercase letter, followed by four lowercase letters , a comma, a space, and one uppercase letter.


grep “[A-Z][a-z][a-z][a-z][a-z][‘,’][‘ ‘][A-Z]” datebook


8.Print lines where the last name begins with K or k .


grep -E “[a-z][‘ ‘][K k]” datebook


9.Print lines preceded by a line number where the salary is a six-figure number.


grep “:[0-9]\{6\}” datebook


10.Print lines containing Lincoln or lincoln (remember that grep is insensitive to case).


grep -e “Lincoln” -e “lincoln” datebook


 
 
 

Comments


©2019 by Oliver Santana. Proudly created with Wix.com

bottom of page