Loading…
Transcript

UNIQ

Uniqify Your Linux Experience

©2021 SiemHunters

Topic

INTRODUCTION

Uniq is a command-line utility in Linux that helps in filtering out the duplicate lines from a file or input stream.

The uniq command works by comparing adjacent lines in a sorted file and removing duplicates.

©2021 SiemHunters

Syntax and Options of Uniq Command

The basic syntax of the uniq command is as follows: uniq [OPTION]... [INPUT [OUTPUT]]

Some of the commonly used options with the uniq command are -c (count the number of occurrences of each line), -d (print only the duplicate lines), -i (ignore case when comparing lines), and -u (print only the unique lines).

©2021 SiemHunters

Examples of Using Uniq in Linux

One example of using the uniq command is to remove duplicate lines from a file.

Another example is to count the number of occurrences of each unique line in a file.

©2021 SiemHunters

Topic

Limitations of Uniq Command

  • While the uniq command is useful for removing duplicate lines from sorted files, it may not work as expected for unsorted files.

  • If there are non-consecutive duplicate lines in a file, then the uniq command will not remove them.

©2021 SiemHunters

Alternatives to Uniq Command

  • One alternative to the uniq command is the awk command, which can be used to filter out duplicate lines from unsorted files as well.

  • Another alternative is the sort command with the -u option, which sorts the file and removes any duplicate lines.

©2021 SiemHunters

Conclusion

  • The uniq command is a useful tool for filtering out duplicate lines from sorted files in Linux.

  • There are alternative commands like awk and sort that can be used for similar purposes.

©2021 SiemHunters

Topic