* Paste Command:
It is used to merge contents of two files vertically.
-d To change the delimiter specified character instead of default delimiter tab
-s Used to join the multiple lines of the file(in parallel) using the delimiters specified.
Syntax1:- paste file1 file2
Syntax2:- paste -d "|" file1 file2
Syntax3:- paste -s file1 file2
Output1:
apple,ball,cat,dog,elephant,fish,goat,hen,icecream,jeep apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream
Output2:
apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream,jeep|apple,ball,cat,dog,elephant,fish,goat,hen,ice- cream
Output3:
apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream,jeep
apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream
* Comm Command:
It compares two sorted files line by line and produces three column output, when no option were passed to it. Column one contains lines unique to file1, column two contains lines unique to file2 and column three contains lines unique to both the files.
-1 Do not display column 1 (Lines unique to first file)
-2 Do not display column 2 (Lines unique to second file)
-3 Do not display column 3 (Lines unique to both file)
--check-order Verify files are in sorted order
--nocheck-order Ignore even if files are not in sorted order
Syntax1:- comm -1 file1 file2
Syntax2:- comm -2 file1 file2
Syntax3:- comm -3 file1 file2
Output1:
apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream
Output2:
apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream,jeep
Output3:
apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream
apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream,jeep
* Diff Command:
It compare files line by line.
This command is used to get uncommon records between both the files.
eg:- diff file1 file2
Syntax1:
diff file1 file2
Syntax2:
diff Proverbs.txt Proverbs2.txt
Output1:
< apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream,jeep
---
> apple,ball,cat,dog,elephant,fish,goat,hen,ice-cream
Output2:
> He who hesitates is lost
> Like father like son
> Fortune favours the brave
* Sort Command:
Sort rearranges the lines of a file such that lines appear in nummerical or alphabetical order.
If no options are given sorting is done as:
Lines that egin with number will come before lines that begin with a letter
Lines that begin with the lowercase letter will come before lines that begin with same letter in uppercase.
-t To specify the delimiter
-k To specify starting and ending columns for sorting
-r To sort in revers order
-n To sort numerical data
-u To remove duplicate lines
-c To check the file is in sorted order or not (It will not sort file contents)
Syntax1:- sort Proverbs.txt
Syntax2:- sort -r Proverbs.txt
Syntax3:- sort -u Proverbs.txt
Syntax4:- sort -c Proverbs.txt
Output1:
Action speaks louder than words
An apple a day keeps the doctor away
An apple a day keeps the doctor away
Better late than never
Practise makes man perfect
Sun sets in the west
Sun rises in the east
Output2:
Sun rises in the east
Sun sets in the west
Practise makes man perfect
Better late than never
An apple a day keeps the doctor away
An apple a day keeps the doctor away
Action speaks louder than words
Output3:
Action speaks louder than words
An apple a day keeps the doctor away
Better late than never
Practise makes man perfect
Sun sets in the west
Sun rises in the east
Output4:-
sort: Proverbs.txt:2: disorder: Sun sets in the west
* Unique Command:
It is used to eliminate or remove the repeated occurance of consecutive lines from the file. If same line is repeated more than once, but not consecutive, it willbe considered as two unique lines and hence not removed. If all the repeated lines of the file has to be removed, then the file has to be sorted before passing it to uniq command.
-u Selecting non repeated lines
-d Selecting the duplicate lines
-c Counting the frequency of occurance.
Syntax1:- uniq Proverbs.txt (one occurance of every records will appear here)
Syntax2:- uniq -u Proverbs.txt
Syntax3:- uniq -d Proverbs.txt
Syntax4:- uniq -c Proverbs.txt
Output1:
Sun rises in the east
Sun sets in the west
An apple a day keeps the doctor away
Practise makes man perfect
Action speaks louder than words
Better late than never
Output2:
Sun rises in the east
Sun sets in the west
Practise makes man perfect
Action speaks louder than words
Better late than never
Output3:
An apple a day keeps the doctor away
Output4:-
1 Sun rises in the east
1 Sun sets in the west
2 An apple a day keeps the doctor away
1 Practise makes man perfect
1 Action speaks louder than words
1 Better late than never
* tr Command: Translating characters
The tr command manipulates individual character in a line. It translates character by character.
It translates each character of expression1 to its corresponding mapped character in expression2.
It takes input only from standard input but not filename as an argument.
-d deleting the characters
-s compressing multiple consecutive characters (Squeeze Repeating Characters)
-c complementing values of expression
The following command is used to translate double quotes into single quotes.
Syntax1:- cat Proverbs.txt | tr -d apple
Syntax2:- cat Proverbs.txt | tr [a-z] [A-Z] (It converts all the character to capital letters)
Syntax3:- echo 'TODAYYYY IIIS SOOO COOOLD ~' | tr -s 'A-Z' 'a-z'
The multiple consecutive characters 'T' in log file logs.txt can be squeezed to one character using option -s of tr command as shown below.
tr -s 'T' < logs.txt
Output1:
Sun riss in th st
Sun sts in th wst
An dy ks th doctor wy
An dy ks th doctor wy
Prctis mks mn rfct
Action sks oudr thn words
Bttr t thn nvr
Output2:
SUN RISES IN THE EAST
SUN SETS IN THE WEST
AN APPLE A DAY KEEPS THE DOCTOR AWAY
AN APPLE A DAY KEEPS THE DOCTOR AWAY
PRACTISE MAKES MAN PERFECT
ACTION SPEAKS LOUDER THAN WORDS
BETTER LATE THAN NEVER
Output3:
today is so cold
* Rev Command : reversing the given text/line
It is used to reverse the text/line character wise. It reverses the order of the characters in each line and prints to the standard output.
Syntax1:- cat file1 | rev
Syntax2:- rev Proverbs.txt
Output1:- peej,maerc-eci,neh,taog,hsif,tnahpele,god,tac,llab,elppa
Output2:
tsae eht ni sesir nuS
tsew eht ni stes nuS
yawa rotcod eht speek yad a elppa nA
yawa rotcod eht speek yad a elppa nA
tcefrep nam sekam esitcarP
sdrow naht reduol skaeps noitcA
reven naht etal retteB
* Grep Command :
The content of the file is processed line by line, to search for the pattern and the lines matching the pattern are displayed on the terminal.
It is used to search for lines of text that match one or many regular expressions.
-i
-V
-n
-x
-c
-v
-l
-f
-E
-P
-A
-B
-C
Syntax:- grep apple Proverbs.txt
Output:-
An apple a day keeps the doctor away
An apple a day keeps the doctor away
* FIND Command :
To find a file in a directory.
Syntax:- find -name s1.sh
* Sed Command :
It is used to replace any character in a file.
Syntax:- sed -i 's/ /,/g' filename.txt
sed -i 's/,/ /g' Proverbs.txt
Without using '-i' in sed command, file will not change it's delimiter or character. Just result will be displayed with 2nd character.