Sort Unique Find Commands
Sort Unique Find Commands
sort Command
The sort command in Windows is used to sort lines of text files or standard input in
ascending order by default. It is commonly used to organize data for easier reading and
processing.
Syntax:
file: The input file to sort (optional). If omitted, sort reads from standard input (e.g.,
piping another command).
Options:
Use:
You can use sort to organize text data alphabetically or numerically. This is
particularly useful when handling large datasets or logs.
Examples:
apple
banana
orange
grape
o Command:
sort fruits.txt
o Output:
apple
banana
grape
orange
2. Sort in Reverse Order:
o Command:
sort /R fruits.txt
o Output:
orange
grape
banana
apple
o Output:
apple
banana
grape
orange
01 apple
02 banana
03 orange
04 grape
o Command:
o Output:
01 apple
04 grape
02 banana
03 orange
2. uniq Command
The uniq command in Windows can be replicated using PowerShell, as Windows doesn't
natively provide uniq like UNIX systems. In PowerShell, Select-Object is used to achieve the
same functionality.
uniq removes or displays only unique lines in a file or input.
It is typically used to eliminate duplicate lines in sorted files.
Syntax in PowerShell:
Options:
PowerShell’s Get-Unique doesn't have many flags like uniq in Linux. However, it can
be combined with other commands to filter unique or duplicate content.
Use:
You can use this combination to remove duplicate lines from sorted files or input.
Examples:
apple
apple
banana
grape
orange
orange
o Command (PowerShell):
o Output:
apple
banana
grape
orange
o Output:
apple
banana
grape
orange
3. find Command
The find command in Windows is used to search for specific text within files or standard
input.
find is used to search for lines that contain a specific string of text in a file or input.
It can also display the count of matching lines or return lines that do not match.
Syntax:
Options:
Use:
You can use find to quickly locate specific text in files, which is useful when working
with large logs or documents.
Examples:
apple is a fruit.
banana is also a fruit.
orange is a citrus fruit.
o Command:
o Output:
apple is a fruit.
banana is also a fruit.
orange is a citrus fruit.
2. Case-Insensitive Search:
o Command:
find /I "FRUIT" data.txt
apple is a fruit.
banana is also a fruit.
orange is a citrus fruit.
o Output:
---------- DATA.TXT: 3
o Output: