Practical No 1 (Linux OS)
Practical No 1 (Linux OS)
1
Aim : Install and configure Linux Operating system environment
https://www.virtualbox.org/
Use the .iso file or ISO file that can be downloaded from the internet and start the virtual box.
Here we need to allocate RAM to virtual OS. It should be 2 GB as per minimum requirement.
Conclusion :
Thus we successfully installed and configure Linux Operating System using Virtual Box.
Practical No. 2
Aim : Use pipe to concatenate the general purpose linux command.
Theory:
Pipes help combine two or more commands and are used as input/output concepts in a command.
In the Linux operating system, we use more than one pipe in command so that the output of one
command before a pipe acts as input for the other command after the pipe.
Syntax:
Command 1 | command 2 | command 3 | ……
Examples:
sort :The data present in the file is unordered. So, This will sort the given file.
Command : cat Branch.txt | sort
Output:
Grep:
The grep filter
searches a file for
a particular
pattern of
characters, and displays all lines that contain that pattern.
Command: $ cat Branch.txt | grep Computer
Output :
head :
Command: $ cat Branch.txt | head -4
Output :
tail :
Command : $ cat Branch.txt |tail -4
Output :
wc :
Command :$ cat Branch.txt | wc
Output :
Conclusion:
As a result, we have performed Shell script by using pipe to concatenate general purpose linux
command.
Practical No.3
Aim : Use pattern searching using grep family commands.
Grep command is used to search for a particular character string in a file.The basic syntax of
the grep command is:
The grep filter searches a file for a particular pattern of characters, and displays all lines that
contain that pattern. The pattern that is searched in the file is referred to as the regular
expression (grep stands for global search for regular expression and print out).
Syntax:
grep [options] pattern filename
Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.
1. Case insensitive search : The -i option enables to search for a string case insensitively in the
given file. It matches the words like “UNIX”, “Unix”, “unix”.
Command :$ grep -i file.txt
Output:
2. Displaying the count of number of matches : We can find the number of lines that matches
the given string/pattern
Command: $grep -c "Linux” file.txt
Output:
3. Display the file names that matches the pattern : We can just display the files that contains
the given string/pattern.
Command: $ grep
Output:
4. Checking for the whole words in a file : By default, grep matches the given string/pattern
even if it is found as a substring in a file. The -w option to grep makes it match only the whole
words.
Command : $ grep -w "system" file.txt
Output:
5. Displaying only the matched pattern : By default, grep displays the entire line which has
the matched string. We can make the grep to display only the matched string by using the -o
option.
Command: $ grep -o "Linux" file.txt
Output:
Conclusion:
Thus we have successfully,performed shell scripting using grep command family for searching
pattern.