Welcome to this comprehensive series of videos where we will be giving solutions and explanations for various BASH challenges from Hackerrank. In this video, we will be addressing 4 tasks, including "'Uniq Command #1" (https://www.hackerrank.com/challenges..., "'Uniq Command #2" (https://www.hackerrank.com/challenges..., "'Uniq Command #3" (https://www.hackerrank.com/challenges..., "'Uniq Command #4" (https://www.hackerrank.com/challenges....
Our goal in this series is to document my thought process and solutions, and to focus on concepts and ideas rather than details. I will also be highlighting the differences between BASH and popular programming languages like Python and JavaScript.
BASH is a powerful command-line interface for interacting with an operating system. It's a shell, and the most popular one. It can be used directly in the terminal or in scripts, which are text files containing a series of instructions. BASH is particularly useful for tasks such as text processing, file operations, connecting multiple programs, and system maintenance. It is also portable, working by default on many platforms.
uniq is a command line utility in Unix-like operating systems that is used to remove duplicate lines from a file. It takes input from a file or from the output of another command through a pipe and prints the unique lines to standard output.
The basic syntax of the uniq command is as follows:
uniq [options] [input_file [output_file]]
Here are some of the most commonly used options:
-c: This option counts the number of occurrences of each line and displays it with the output.
-d: This option only displays lines that are duplicated.
-i: This option ignores case distinctions in both the input and the comparison of lines.
-u: This option only displays lines that are unique (non-duplicated).
If an input_file is specified, uniq reads the file and removes any consecutive duplicate lines. If an output_file is specified, uniq writes the output to that file instead of printing it to the standard output.
Here's an example usage of the uniq command:
$ cat example.txt
apple
banana
banana
cherry
apple
$ uniq example.txt
apple
banana
cherry
apple
$ uniq -c example.txt
2 apple
2 banana
1 cherry
In the above example, uniq removes the consecutive duplicate lines and prints the unique lines to the standard output. The -c option is used to count the number of occurrences of each line in the input file.
If you want to see all the solutions for these challenges, you can find them on my Github repository: https://github.com/djeada/Bash-Hacker...
Also, you can find me on my website: https://adamdjellouli.com/ where I write about different programming topics, and you can see my other projects.
Don't forget to like and subscribe for more BASH tutorials and solutions to Hackerrank challenges.