1

i have to check a licence of a product which i can by just typing

checklicence 

in commandline.

it gives me output:

Product License status

Parameters of license Sxxxxx--xxxxx--xxxxx4


Volume
    Regular texts
        Units: Pages
        Quantity: 120000 per year
        Remains: 107852 this year

i want to find just how many remain's are there and print that.

So i tried of doing

 >checklicense |grep -i "Remains:"

i am getting output as

>Remains: 107852 this year

But i just want the number 107852 as output

Is there any way how to do this?

my grep version is License GPLv3+: GNU GPL version 3

3
  • @Inian License GPLv3+: GNU GPL version 3 Commented Apr 11, 2017 at 6:09
  • 1
    Find my answer below and let me know if it solved your problem Commented Apr 11, 2017 at 6:51
  • Possible duplicate of Regex to extract only text after string and before space Commented Apr 11, 2017 at 7:30

2 Answers 2

1

You can use the -P flag from the GNU grep along with the -o flag to match only the part we are looking for,

checklicence | grep -oP 'Remains:\s\K([^ ]\d+)'
107852

The -P flag in GNU grep is to enable the Perl Compatible Regular Expressions library.

\K: This sequence resets the starting point of the reported match. Any previously matched characters are not included in the final matched sequence.

RegEx Demo


Also worth adding that the man grep page says

This is highly experimental and grep -P may warn of unimplemented features.

Sign up to request clarification or add additional context in comments.

Comments

1
Checklicense |grep -i "Remains:" | grep -o "[0-9]*"

This would get only the numeric part of the the result of the first grep

2 Comments

what does grep -o do?
-o display the part only matching a specific format ,since only numeric is required [0-9]* wildcards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.