I have created a file called histcopy.txt with the command history, (history > histcopy.txt). It look somewhat like this: 1. l 2. ls 3. cat necopy.txt 4. netstat 5. cd | ls-l ; grep -i 3 histcopy.txt | echoAnd I want to print out each unique command, this is the command I run so far:awk '{print $2}' histcopy.txt | sort|uniq`And the outcome of that is:llscatnetstatcdBut in the last line (5. cd | ls-l ; grep -i 3 histcopy.txt | echo), there are many commands that it ignores and only takes the first cd. How can I rewrite my current command so that it extracts them as well? So that from the 5th line it would also extract:ls-lgrep -i 3: histcopy.txtechomaking of them separate items in the output list.
Extract unique single commands from history
linux;shell;command line;sort
$ cat histcopy.txt  1 l 2 ls 3 cat necopy.txt 4 netstat 5 cd | ls -l ; grep -i 3 histcopy.txt | echo$ sed 's/^\s*\S*\s*//' histcopy.txt | tr ';|' '\n' | awk '!seen[$1]++{print $1}'llscatnetstatcdgrepechosed 's/^\s*\S*\s*//' to remove initial space and number associated with command in history outputtr ';|' '\n' replace ; and | with newline characters. This will work for current problem statement, but won't help if there are commands inside substitutions, etcawk '!seen[$1]++{print $1}' unique commandsSimilar logic implemented with perl alone$ perl -lne 's/^\s*\S+//; (@a)= split/[;|]/; foreach (@a){($k) = /^\s*\K(\S+)/; print $k if !$seen{$k}++}' histcopy.txt llscatnetstatcdgrepecho