Reputation: 10281
I have:
$ module avail firefox --latest
---------------------------------------------------------- /env/common/modules -----------------------------------------------------------
firefox/83.0
I would like to extract the firefox/83.0
part of the above result into a new command:
$ module load firefox/83.0
This is what I have so far, but it does not seem like I can pipe the result from the grep
onto the next command:
$ module avail firefox --latest | grep firefox | echo module load
Note: this is on a version of Modules which does not have the module load app/latest
ability.
Upvotes: 0
Views: 154
Reputation: 43964
Use a regex to capture only firefox/83.0
, then use command substitution to use that result in the next command;
module load $(module avail firefox --latest | sed -nre 's/^firefox\/[^0-9]*(([0-9]+\.)*[0-9]+).*/\0/p'
More info on the regex: How to extract a version number using sed?
Using xargs
;
module avail firefox --latest | sed -nre 's/^firefox\/[^0-9]*(([0-9]+\.)*[0-9]+).*/\0/p' | xargs module load
Upvotes: 1
Reputation: 140970
it does not seem like I can pipe the result from the grep onto the next command:
You can, but you need to use other command, that will read from the pipe and add it as command arguments. As simple as:
$ module avail firefox --latest | grep firefox | xargs module load
Upvotes: 0
Reputation: 12877
module load "$(module avail firefox --latest | grep -Eo 'firefox\/[[:digit:]]+\.[[:digit:]]+')"
Use the output of the module avail command and then search for firefix, followed by a / and then a digit one or more times, a full stop and then a digit one or more times. use this output as part of the module load command
Upvotes: 0