I'm developing a custom shell. In this assignment, I need to implement uniq-like command. Given sorted lines, uniq should be able to print all unique values and (their number of occurences if the command is uniq -c). Example code is stated at the very end.
I have no problem with the algorithm. I wrote a function which can do take exactly same operation with desired one. However, the problem is that, what are these types of outputs and inputs? I mean when I command cat input.txt, are these lines just one string or are they given in array? As I said, algorithm is ok but I do not know how to apply that correct algorithm in the shell? Any help or idea is appreciated.
$cat input.txt
Cinnamon
Egg
Egg
Flour
Flour
Flour
Milk
Milk
$cat input.txt | uniq
Cinnamon
Egg
Flour
Milk
These lines are the result of a fork, just strings that have been sent to
stdout.getlineis very useful in these cases, now that you have the algorithm, you only have to process the output ofcat.An example:
Output: