You are on page 1of 17

Hi, welcome to ASE,

cat : To display the contents of a file. Bangalore


Example:
$gedit t1.txt
$cat t1.txt
Hi, welcome to ASE, Bangalore
Incase, if you require to enter the contents to the file in the prompt
itself. It is possible by using > (redirection operator) to perform the
same.

$cat > file1


Welcome CSE – C section lab ctrl+z
$cat file1
Welcome CSE – C section lab
wc: This command helps us in getting the count of words &
lines of a file.

$gedit t2.txt
t2.txt(gedit)
$cat t2.txt Welcome to CSE
Welcome to CSE Welcome to Bangalore campus
Welcome to Amrita
Welcome to Bangalore campus
Welcome to Amrita
$wc t2.txt
$man wc
$wc –w t2.txt
$wc –l t2.txt
comm : compares two sorted files line by line
$cat > movie1
Mad mad world
Ten commanments
Jurassic park
Independence day
$cat > movie2
Kabali
Annamalai
Padayappa
Indian
$comm movie1 movie2
cmp: compares two files byte by byte
Syntax: cmp file1 file2
$cmp movie1 movie2

$man cmp

diff: Compares two files line by line


Syntax: diff file1 file2

$diff movie1 movie2

who: This command gives ther version and terminal number.


$who

who am i: Displays the details of the current user.


$whoami
cal : This command displays the calendar of the month

$cal
$man cal
comm compare two sorted files line by line and write to standard output; the
lines that are common and the lines that are unique.

Example: Let us suppose there are two sorted files file1.txt and file2.txt and
now we will use comm command to compare these two.
// displaying contents of file1.txt //
$cat file1.txt
Apaar
Ayush Rajput
Deepak
Hemant

// displaying contents of file2.txt //


$cat file2.txt
Apaar
Hemant
Lucky
Pranjal Thakral
• The above output contains of three columns where first
column is separated by zero tab and contains names only
present in file1.txt ,
• second column contains names only present in file2.txt and
separated by one tab and
• the third column contains names common to both the files
and is separated by two tabs from the beginning of the line.
diff stands for difference. This command is used to display the differences in the files by comparing the files line by
line. Unlike its fellow members, cmp and comm, it tells us which lines in one file have is to be changed to make the
two files identical.
The important thing to remember is that diff uses certain special symbols and instructions that are required to
make two files identical. It tells you the instructions on how to change the first file to make it match the second file.
Special symbols are:
a : add
c : change
d : delete
The first line of the diff output will contain:
•Line numbers corresponding to the first file,
•A special symbol and
•Line numbers corresponding to the second file.

Like in our case, 0a1 which means after lines 0(at the very beginning of file) you have to add Tamil Nadu to match
the second file line number 1. It then tells us what those lines are in each file preceeded by the symbol:
•Lines preceded by a < are lines from the first file.
•Lines preceded by > are lines from the second file.
•Next line contains 2,3c3 which means from line 2 to line 3 in the first file needs to be changed to match line number
3 in the second file.
• 5c5 means line 5 in the first file needs to be changed to match line number 5 in the second file. It then tells us those
lines with the above symbols.
cmp - Compare two files, and if they differ, tells the first byte and line number where they differ.
• 'cmp' reports the differences between two files character by character, instead of line by line.
• As a result, it is more useful than 'diff' for comparing binary files. For text files, 'cmp' is useful
mainly when you want to know only whether two files are identical.
• For files that are identical, 'cmp' produces no output. When the files differ, by default, 'cmp'
outputs the byte offset and line number where the first difference occurs.
Filter commands :
• Sort commands
• Cut
• Head
• Tail
• grep
• tr and
• paste

SORT command is used to sort a file, arranging


the records in a particular order. By default, the
sort command sorts file assuming the contents
are ASCII. Using options in sort command, it
can also be used to sort numerically.
The cut command in UNIX is a command for cutting out the sections from each line of files and writing the
result to standard output. It can be used to cut parts of a line by byte position, character and field
It is the complementary of tail command. The head
command, as the name implies, print the top N
number of data of the given input. By default, it
prints the first 10 lines of the specified files.
grep - to select non matching files
-v is to select non matching Lines
-c is suppresses normal output and instead prints the count of
matching lines for each input in file

1) sort stores.txt
2) cut -d ":" -f 1,2,5 stores.txt
3) grep 'y'stores.txt | cut -d ":" -f 1,2,5
4) </ Question Not given/>
5) cut -d ":"-f 2 stores.txt | sort>sorted
6) cat sorted
7) cut -d ":"-f 1,3 stores.txt | sort -t ":" -nk2
8) head -n 3 sorted
9) cut -d ":"-f 1 stores.txt | tr -s'0' cat stores.txt
10) grep -c "100" stores.txt cat stores.txt

You might also like