Professional Documents
Culture Documents
$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
$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
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
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