Tried finding an answer on stackoverflow but can't. All answers were with awk and sed which I'm not allowed to use! So once again, I ask you to help me.
Basically I need to write a script that prints out the history of all used commands in the linux terminal. The commands are saved in a file which is put as the first argument of the script. Command "/bin/bash" equals bash so we don't mix things up. So, the print out should be sorted from commands with most occurrences to commands with least occurrences. Those with the same number of occ should be sorted in alphabetical order.
And, if we put switch -n the script only prints out the first n commands. And with switch -p we also include the commands that are part of the pipeline.
Example of history.txt;
ls -al
bash
cat datoteka.txt
cat d.txt | sort | less
/bin/bash
What the script should print out;
./hstat.sh history.txt
2 bash
2 cat
1 ls
As I'm fairly new to BASH programming and not really good at it, I would love some help with this. Where to start, some useful examples, maybe some code or even a lot of it :P Of course, with explanation or else it would be useless for me to just copy it.