Professional Documents
Culture Documents
21MCA2234 Linux Worksheet 2.1
21MCA2234 Linux Worksheet 2.1
A filter is a program that reads standard input, performs an operation upon it and writes the
results to standard output. For filtering the data, we can use Linux Filter Commands.
There are various commands that are known as filter commands such as
Head
Tail
Uniq
Sed
Wc
sort
2. Task to be done:
Enlist all files that start with f and have i or R as second character and end with a number
from range 0-6. Write a command to search the word Good or good and have any integer
from 0-9 at the end of that word. Exemplify egrep and fgrep for searching above pattern.
List all files starting with word File and having any digit as fifth character and nothing
else. List all files starting with a letter and ending in a number.
Create a file using vi editor named filters.txt. Enter the content in that file as follows:
“Anyone who has never made a mistake has never tried anything new.”
Albert Einstein
After creating a file, count the characters only of a file. Sort the contents and check if
there is any duplicate content exists. After that, display the line numbers using cat
command. Check the occurrences of word “has” using quantifiers. Search a word “never”
which is preceded by a word “made” and replace it with a word “NEVER”.
3. Concept used:
Filter Commands:
Wc : Using this command, we can count word in file along with word count,character
count and line count
Syntax: wc filename
Syntax: nl filename
head: head is used to display the first parts of a file, it outputs the first 10 lines by default.
tail: tail outputs the last parts (10 lines by default) of a file.
cat: The cat (short for “concatenate“) command is one of the most frequently used
command in Linux/Unix like operating systems. cat command allows us to create single or
multiple files, view contain of file, concatenate files and redirect output in terminal or files.
-n: use –n to display the content of file along with line numbers
-e: use –e to display the content of file along with end of line
Tac : tac command in Linux is used to concatenate and print files in reverse
uniq: uniq command is used to report or omit repeated lines, it filters lines from standard input
and writes the outcome to standard output.
tee: tee reads the standard input and write it to both standard output and on one or more files
cut: cut command is used to cut out selected fields (columns) of each line of a file, depending
on a delimiter or a count of bytes.
sed:Sed is a stream editor. A stream editor is used to perform basic text transformations on an
input stream (a file or input from a pipeline).
Enlist all files that start with f and have i or R as second character and end with a number
from range 0-6. Write a command to search the word Good or good and have any integer
from 0-9 at the end of that word. Exemplify egrep and fgrep for searching above pattern.
List all files starting with word File and having any digit as fifth character and nothing
else. List all files starting with a letter and ending in a number.
Steps/Commands involved to perform Question1 is:-
1. Create files are file1, from, file1234 and file26 and add content in file26 is good
good234, Good456.
2. To enlist all files that start with f and have i or R as second character and end with a
number from range 0-6 by using command ls f[i,r]*[0-6] .
3. To search the word Good or good and have any integer from 0-9 at the end of that
word by using command egrep “[G,g]ood[0-9]” file26
4. List all files starting with word File and having any digit as fifth character and nothing
else by using command ls file[0-9]
5. List all files starting with a letter and ending in a number by using command ls [a-
z]*[0-9].
Output:
Output of 1:
Output 2:
Learning outcomes (What I have learnt):
Evaluation Grid: