Practical 3 OS
Practical 3 OS
PRN:- 24025081245513
Practical No. 03
Aim:- Shell Script programming using the commands grep,awk,and sed
Grep is able to find the configuration named ErrorLog in your Apache configuration file and
returns the text as output. The output returned by most Linux distributions highlights the search
term in red.
To search multiple files using grep, separate each filename with a whitespace character. When
grep searches multiple files, its output displays the location of each file where the search term is
found.
grep "rollover" /var/log/fail2ban.log /var/log/fail2ban.log.1
Sed Command
Sed is short for Stream Editor and has much of the same functionality as grep. However, sed is
much more flexible in how it can select lines of input. It also lets you modify the data it finds. Sed
opens a file, reads it line by line, and acts on each line according to its instructions. If you are new
to sed, its syntax can may seem difficult to understand. Once youre used to seds syntax, you can
accomplish powerful operations on your text files and data.
Create a Search and Replace sed Script
The most common usage of sed is to search for strings or patterns throughout a file and replace
them with different strings. For instance, to replace every instance of Copyright 2020 with
Copyright 2021 in a group of HTML files, use the following command:
AWK Command
AWK is the most powerful of the three tools explored in this guide. It is a full-featured
programming language with functions, variables, flow control, and support for different data
types.
AWKs primary use cases are the following:
Processing field-oriented data
Numeric comparisons and calculations
Modifying data based on calculations
awk '($3 == "Toyota") {print} names.txt