Answer the question
In order to leave comments, you need to log in
How to extract program names from command in bash?
Suppose we have a command history file like this:
sudo ls | awk '!($NF ~ /\.[a-z]+$/)'
for i in ~/*; do echo $(locate -c -r $i) $i; done | pv | sort -nr | bcat -t
for f in *.zip; do unzip $f; done
RACK_HANDLER=falcon rails s
sudo ls awk
pv sort bcat
unzip
rails
Answer the question
In order to leave comments, you need to log in
this can be quite easily implemented on the bash itself in a few lines, if ruby is needed, then you can simply take as a starting point for your implementation
the list of all programs located in the $ PATH
list, or rather the description of the builtin ( builtin ) commands in the bash shell can be look with the help command, but
I think it would be more correct to use type to determine the type of command
$ ls ${PATH//:/ } |awk 'NF && !/:$/'
$ help
$ type -t rg
file
$ type -t cd
builtin
$ type --help
...
-t output a single word which is one of `alias', `keyword',
`function', `builtin', `file' or `', if NAME is an alias,
shell reserved word, shell function, shell builtin, disk file,
or not found, respectively
$ for i in $(ls ${PATH//:/ } |awk 'NF && !/:$/');do && echo $i;done > file.txt
sudo ls | awk '!($NF ~ /\.[a-z]+$/)'
for i in ~/*; do echo $(locate -c -r $i) $i; done | pv | sort -nr | bcat -t
for f in *.zip; do unzip $f; done
RACK_HANDLER=falcon rails s
$ grep -o -w -n -f file.txt test.txt
1:sudo
1:awk
2:pv
2:sort
3:zip
3:unzip
$ grep -o -w -n -f file.txt test.txt |awk -F: '{if($1!=i){printf $2" "}else{print $2};i=$1}'
sudo awk
pv sort
zip unzip
sudo ls awk
pv sort bcat
unzip
rails
for f in *.zip; do unzip $f; done
$ for i in $(ls ${PATH//:/ } |awk 'NF && !/:$/');do && echo $i;done > file.txt
$ grep -o -w -n -f file.txt test.txt |awk -F: '{if($1!=i){printf $2" "}else{print $2};i=$1}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question