191 likes | 382 Views
GNU Grep. What is GNU?. GNU is an operating system which is 100% free software. It was launched in 1983 by Richard Stallman and has been developed by many people working together for the sake of freedom of all software users to control their computing
E N D
What is GNU? • GNU is an operating system which is 100% free software. • It was launched in 1983 by Richard Stallman and has been developed by many people working together for the sake of freedom of all software users to control their computing • It works as a free software foundation of open source tools. • Check this websit https://www.gnu.org/software/
What is Grep? • Grep (Global Regular Expression Print) searches one or more input files for lines containing a match to a specified pattern. By default, Grep outputs the matching lines. • Is installed by default on almost every distribution of Linux, BSD and UNIX, and is even available for Windows. • Download from: http://gnuwin32.sourceforge.net/packages/grep.htm
GREP • There are two ways to provide input to Grep, each with its own particular uses. • First, Grep can be used to search a given file or files on a system (including a recursive search through sub-folders). • Grep also accepts inputs from another command or series of commands.
Regular expressions • A regular expression, often shortened to “regex” or “regexp”, is a way of specifying a pattern (a particular set of characters or words) in text that can be applied to variable inputs to find all occurrences that match the pattern. • regular expressions are included in the Grep command in the following format:
Environment variable • An environment variable is a dynamic "object" on a computer that stores a value, which in turn can be referenced by one or more software programs in Windows. • In other words it stores a reference for the regularly used software tools in one path.
Grep Commands • Open The CMD, Write the command grep • Grep –help briefly summarizing the command-line options
Grep Commands • Create a txt file on which we will run our Grepsearches • the file contains the following lines: Hi this is test file to carry out few regular expressions practical with grep 123 456 Abcd ABCD
Try this commands grep -i “abcd” testfile grep -w “test” testfile grep -B2 “Abcd” testfile grep “[a-z]” testfile grep “[A-Z]” testfile
Line and word anchors • The ^ anchor specifies that the pattern following it should be at the start of the line: grep“^th” testfile • The $ anchor specifies that the pattern before it should be at the end of the line: grep“i$” testfile • The operator \> anchors the pattern to the end of a word. grep“le\>” testfile