Podcast
Questions and Answers
What does the grep
command do?
What does the grep
command do?
The grep
command is used to search for a pattern of characters in a file and display the matching lines.
What is the purpose of regular expression in searching text?
What is the purpose of regular expression in searching text?
Regular expression provides the ability to match a string of text in a flexible and concise manner.
What does the -w
option do in the grep
command?
What does the -w
option do in the grep
command?
By default, the grep
command is Case-Sensitive.
By default, the grep
command is Case-Sensitive.
Signup and view all the answers
How can you make the grep
command Case-Insensitive?
How can you make the grep
command Case-Insensitive?
Signup and view all the answers
What is the purpose of the -v
option in the grep
command?
What is the purpose of the -v
option in the grep
command?
Signup and view all the answers
Which option in the grep
command will print `N' lines after the matched line?
Which option in the grep
command will print `N' lines after the matched line?
Signup and view all the answers
Which option in the grep
command will print 'N' lines before the matched line?
Which option in the grep
command will print 'N' lines before the matched line?
Signup and view all the answers
Which option in the grep
command will print 'N' lines around the matched line?
Which option in the grep
command will print 'N' lines around the matched line?
Signup and view all the answers
What are aliases in Linux?
What are aliases in Linux?
Signup and view all the answers
How do you list all defined aliases in Linux?
How do you list all defined aliases in Linux?
Signup and view all the answers
How to define an alias temporarily in Linux?
How to define an alias temporarily in Linux?
Signup and view all the answers
How to define an alias permanently?
How to define an alias permanently?
Signup and view all the answers
How do you remove an alias in Linux?
How do you remove an alias in Linux?
Signup and view all the answers
Study Notes
Network Operating Systems - GREP and Aliasing
- Regular expressions allow flexible and concise matching of text strings. Text strings can be a single character, word, sentence or a pattern of characters.
GREP Command
-
grep
(Global Regular Expression Print) command prints lines of text matching a regular expression. -
Displays a list of lines matching a pattern within a text file.
-
The presented examples use
grep
with a target text file namednames.txt
. This file contains a list of names.
Searching in Files
- To find a specific line in
names.txt
, usegrep "Brad William" names.txt
.
Whole Word Match
- Using
grep -w "Brad Williamson"
ensures only complete words match.
Case-Insensitive Search
-
grep -i "Chris Evans"
orgrep -wi "Chris Evans"
perform a case insensitive search.
Line Numbering
-
grep -n "Chris Evans"
displays the line number of matching lines.
Displaying Lines Around Matches
-
grep -A 2 "Chris Evans"
shows the matched line and the two following lines. -
grep -B 2 "Chris Evans"
displays the matched line and the two preceding lines. -
grep -C 2 "Chris Evans"
shows the matched line and the two lines before and after the matched line.
Printing Only Matched Strings
-
grep -o "Chris"
prints only the matched substring "Chris". -
grep -oi "Chris"
performs the same operation while ignoring case. - Using the
-o
option to extract matched strings only instead of complete lines.
Aliases
- Aliases are custom shortcuts for commands or sets of commands.
- Aliases are only active during a specific shell session.
Listing Aliases
- The
alias
command displays defined aliases.
Defining Aliases Temporarily
-
alias shortname='your custom command here'
sets a temporary alias; the alias is discarded when the current session ends.
Defining Aliases Permanently
- Defining an alias permanently requires modification of the
.bashrc
file. These changes make the alias available for all subsequent sessions using the same shell. A.bashrc
example was given.
Removing Aliases
-
unalias ls
removes the alias for a command.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge on the GREP command in Network Operating Systems. This quiz covers key concepts such as regular expressions, case-insensitive searches, and line numbering. Prepare to demonstrate your understanding of searching through text files effectively.