Skip to content

Instantly share code, notes, and snippets.

@mohitesachin217
Created June 19, 2016 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohitesachin217/aa354b454368ef5ca5827016c1626a12 to your computer and use it in GitHub Desktop.
Save mohitesachin217/aa354b454368ef5ca5827016c1626a12 to your computer and use it in GitHub Desktop.
search textfiles with regular expressions
--grep,
--fgrep,
--egrep
--regex
grep search through stream
syntax
grep [string to find] [file name]
grep -n[string to find] ] [filename]
grep is case sensitive to make case insensitive add -i flag
regular expressions inside the grep
^ == means == starts with grep ^boo file.txt == list all the lines with boo starting
$ == means == ends with grep oks$ file.txt == list all the lines with oks ending
. == means == any single character grep .oo file.txt == list all the lines with any character start but oo next characters
egrep: grep with more regular expression
egrep '^(b|d)' file.txt search all the words that starts with either b or d
egrep '(b|d)oo' file.txt search all the words that starts with b or d and followed by oo
fgrep dosent support any kind of regular expresstion
man regex command for more information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment