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?
- It ignores the line of the searched string.
- It searches for the entire word only. (correct)
- It searches for the matched line number.
- It searches for the entire pattern only
By default, the grep
command is Case-Sensitive.
By default, the grep
command is Case-Sensitive.
How can you make the grep
command Case-Insensitive?
How can you make the grep
command Case-Insensitive?
What is the purpose of the -v
option in the grep
command?
What is the purpose of the -v
option in the grep
command?
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?
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?
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?
What are aliases in Linux?
What are aliases in Linux?
How do you list all defined aliases in Linux?
How do you list all defined aliases in Linux?
How to define an alias temporarily in Linux?
How to define an alias temporarily in Linux?
How to define an alias permanently?
How to define an alias permanently?
How do you remove an alias in Linux?
How do you remove an alias in Linux?
Flashcards
String
String
A sequence of characters, like a word, sentence, or even a single character.
grep
grep
A tool that allows you to search for specific patterns within text files, using a special language called 'regular expressions.'
Regular Expression
Regular Expression
A special type of text pattern that uses specific characters and symbols to match and find text in files.
grep Command
grep Command
Signup and view all the flashcards
names.txt
names.txt
Signup and view all the flashcards
'-w' option
'-w' option
Signup and view all the flashcards
'-i' option
'-i' option
Signup and view all the flashcards
'-n' option
'-n' option
Signup and view all the flashcards
'-v' option
'-v' option
Signup and view all the flashcards
'-A' option
'-A' option
Signup and view all the flashcards
'-B' option
'-B' option
Signup and view all the flashcards
'-C' option
'-C' option
Signup and view all the flashcards
'-o' option
'-o' option
Signup and view all the flashcards
Alias
Alias
Signup and view all the flashcards
alias
alias
Signup and view all the flashcards
Temporary Alias
Temporary Alias
Signup and view all the flashcards
'.bashrc' file
'.bashrc' file
Signup and view all the flashcards
alias shortname='your custom command here'
alias shortname='your custom command here'
Signup and view all the flashcards
Edit '.bashrc' file and add alias shortname='your custom command here'
Edit '.bashrc' file and add alias shortname='your custom command here'
Signup and view all the flashcards
unalias lsl
unalias lsl
Signup and view all the flashcards
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.