$ egrep -i by:(.*)$ test.txt By: Tobias Highfill What is grep? In - - PowerPoint PPT Presentation

egrep i by test txt
SMART_READER_LITE
LIVE PREVIEW

$ egrep -i by:(.*)$ test.txt By: Tobias Highfill What is grep? In - - PowerPoint PPT Presentation

$ egrep -i by:(.*)$ test.txt By: Tobias Highfill What is grep? In UNIX systems grep is a command line tool to search files using regular expressions. What are regular expressions? Regular expressions are strings used for pattern matching.


slide-1
SLIDE 1

$ egrep -i by:(.*)$ test.txt

By: Tobias Highfill

slide-2
SLIDE 2

What is grep?

In UNIX systems grep is a command line tool to search files using regular expressions. What are regular expressions? Regular expressions are strings used for pattern matching. What are strings? How did you get into this class?

slide-3
SLIDE 3

Regex crash course

  • Most characters stand for themselves
  • Metacharacters represent other characters

and can only be represented by escaping

  • Sections of text can be captured using

parenthesis

  • Characters like “*” “+” and “?” allow

segments to repeat

slide-4
SLIDE 4

Example regex

by:(.*)$

  • Normal characters
  • Capturing group
  • Repeat character (0 or more times)
  • Metacharacters

○ “.” matches any character ○ “$” matches the end of the line

slide-5
SLIDE 5

Different grep flavors

  • grep

○ vanilla, normal

  • egrep

○ extended grep with additional character support

  • fgrep

○ “fast grep,” doesn’t use regex so it’s way faster

slide-6
SLIDE 6

How to use grep

grep commands have three sections:

  • 1. Options*
  • 2. Pattern
  • 3. Files*

*optional grep [OPTIONS]... PATTERN [FILES]...

slide-7
SLIDE 7

Wait files are optional?

  • If no files are provided grep will read the

standard input and analyze that.

  • This makes grep amazing for piping.
  • Don’t want to read the entire man page for a

program? Grep for keywords! man gcc | fgrep -in target

slide-8
SLIDE 8

Common grep options

  • -c, --count
  • -e regexp, --regexp=regexp
  • -f file, --file=file
  • -i, --ignore-case
  • -h, --no-filename
  • -l, --files-with-matches
  • -n, --line-number
  • -s, --no-messages
  • -v, --invert-match
  • -x, --line-regexp
slide-9
SLIDE 9

When am I ever gonna use this?

  • Searching large files for pertinent information
  • Searching your file system for a particular

pattern

  • Great for piping!
  • Finding the source code for your regex golf

solver

Source: xkcd.com/1313

slide-10
SLIDE 10

Demonstration

I will now demonstrate grep using cygwin