We will discuss about
1) Combining contents of two files in Unix
2) Sort & Get the Unique Lines (delete duplicate lines)
3) How to get only the duplicate lines
4) How to get only the unique lines
Suppose we have two files a.txt and b.txt as mentioned below :
a.txt
b.txt
1) Combining contents of two files in Unix
Combining contents of both a.txt & b.txt into c.txt
]# cat a.txt b.txt > c.txt
]# cat c.txt | sort | uniq
3) How to get only the duplicate lines
]# cat c.txt | sort | uniq -u
4) How to get only the unique lines
5) How to get sort by ignore case
]# cat requirements.txt | sort --ignore-case > requirements_bak.txt
Please refer to other topics on Unix like :
Unix Grep Examples
Search a Directory in Unix
Unix For Loop
pushd & popd in Unix
Find Size of Directory
Word Count
Please refer to other topics on AWK like :
Awk Examples
Print First Two Columns of File
Print Last Two Columns of File
Please refer to other topics on Dict like :
Dict in Python
Dict keys and values in Python
Please refer to other topics on List like :
List in Python
Append to list in Python
Delete the last name from the list in Python
Remove an element from List in Python
Check an element exists in an list in Python
Python Filter Vs Map Vs List Comprehension
Please refer to other topics on File Concepts like :
Print File Content in Python
Print File in Reverse Order in Python
Please refer to Regular Expressions Concepts :
Brief on Regular Expressions
Greedy Operators in Regular Expressions in Perl
Modifiers in Regular Expressions in Perl
Capturing concept in Regular Expressions in Perl
Capture Pre Match ,Post Match, Exact match in Regular Expressions in Perl
Non Capturing Paranthesis in Regular Expressions in Perl
Substitute nth occurance in Regular Expressions in Perl
All Topics in Regular Expressions in Perl
You might also wish to read other topics like :
Python Class and Object Example
Inheritance in Python
Packages in Python
Exceptions in Python
How to remove duplicate lines from a file in Perl
How to remove duplicate lines from a file in Pyhton
1) Combining contents of two files in Unix
2) Sort & Get the Unique Lines (delete duplicate lines)
3) How to get only the duplicate lines
4) How to get only the unique lines
Suppose we have two files a.txt and b.txt as mentioned below :
a.txt
10 20 30 40 50
b.txt
10 20 30 40 50 60 70 80
1) Combining contents of two files in Unix
Combining contents of both a.txt & b.txt into c.txt
]# cat a.txt b.txt > c.txt
10 20 30 40 50 10 20 30 40 50 60 70 802) Sort and Get the Unique Lines (delete duplicate lines)
]# cat c.txt | sort | uniq
10 20 30 40 50 60 70 80
3) How to get only the duplicate lines
]# cat c.txt | sort | uniq -u
60 70 80
4) How to get only the unique lines
10 20 30 40 50
5) How to get sort by ignore case
]# cat requirements.txt | sort --ignore-case > requirements_bak.txt
Please refer to other topics on Unix like :
Unix Grep Examples
Search a Directory in Unix
Unix For Loop
pushd & popd in Unix
Find Size of Directory
Word Count
Please refer to other topics on AWK like :
Awk Examples
Print First Two Columns of File
Print Last Two Columns of File
Please refer to other topics on Dict like :
Dict in Python
Dict keys and values in Python
Please refer to other topics on List like :
List in Python
Append to list in Python
Delete the last name from the list in Python
Remove an element from List in Python
Check an element exists in an list in Python
Python Filter Vs Map Vs List Comprehension
Please refer to other topics on File Concepts like :
Print File Content in Python
Print File in Reverse Order in Python
Please refer to Regular Expressions Concepts :
Brief on Regular Expressions
Greedy Operators in Regular Expressions in Perl
Modifiers in Regular Expressions in Perl
Capturing concept in Regular Expressions in Perl
Capture Pre Match ,Post Match, Exact match in Regular Expressions in Perl
Non Capturing Paranthesis in Regular Expressions in Perl
Substitute nth occurance in Regular Expressions in Perl
All Topics in Regular Expressions in Perl
You might also wish to read other topics like :
Python Class and Object Example
Inheritance in Python
Packages in Python
Exceptions in Python
How to remove duplicate lines from a file in Perl
How to remove duplicate lines from a file in Pyhton