Artificial intelligent assistant

Using Regex from command line to extract number I am using a tool to calculate cylomatic complexity of a javascript file. Example: jsc --minimal test.js This command will give the following output. File LOC Cyclomatic Halstead difficulty /home/shray/test.js 23 4 10 Cyclomatic: min 4 mean 4.0 max 4 Halstead: min 10 mean 10.0 max 10 Now I use jsc --minimal test.js | grep "Cyclomatic:" which gives me output as Cyclomatic: min 4 mean 4.0 max 4 Now I have a regex, `Cyclomatic:[\s]*min[\s]+([0-9]+)` but I am not able to use it to extract the number showing minimum Cylomatic value. Any help how can I just ouput the value of Min or Max Cyclomatic complexity value on the terminal output?

If you know that this line is always of the same format, you can use a simple `cut`:


cut -d' ' -f3


or with `awk` you can do the whole thing including your first `grep`:


awk '$1 == "Cyclomatic:" {print $3}'


If the line might change, use `sed`:


sed -E 's/.*( min )([0-9]+).*/\2/'


or `grep -P` if available:


grep -Po ' min \K[0-9]+'


or normal `grep`:


grep -o 'min [0-9]\+'


This returns `min 4`, which you can easily filter adding another `grep` or `cut`


grep -o '[0-9]\+$'
# or
cut -d' ' -f2

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 01db59fc3afffec7b5bc4b33a4e7098b