user3894937
user3894937

Reputation: 73

Identifying all unix commands from a file

I need to scan through a file which has some unix shell commands and its output. I need to extract the list of unix commands mentioned throughout the file and list them down onto a different file. One way to achieve it to scan through the file for some specific list of commands and if present to redirect them to a different file. But this gets difficult as the list kept growing. Any other ideas in this line. TIA

Upvotes: 0

Views: 199

Answers (1)

Matt
Matt

Reputation: 646

You can get a list of all commands available in bash with compgen. If you want to use a whitelist approach, you could store the output of compgen -ac (aliases and commands) in a file and then check each token in your input file against that list.

More details on usage of compgen can be found on this answer.

Upvotes: 1

Related Questions