Click here to Skip to main content
16,022,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I give below command
$ /abc/tej --version
output-
abc version = 1234R
xyz Version = P2vfs(5.1.5-1)

I want to grep the above command so that i get only 5.1 value.

I did it using /abc/tej --version | grep ^xyz | sed 's/.*(//' | head -c 3.

Can anyone help me to get a simpler command or regex to get the substring

Thanks in advance.
Posted

1 solution

As a regex it's pretty simple:
(?<=Version = .*?\()\d+\.\d+(?=\.\d+-\d+\))
 
Share this answer
 
Comments
Member 12018498 21-Jan-16 6:20am    
Thank you for suggestion. and sorry, i didn't get you. I am new to regex or grep usage, Do you mean use this regex for grepping?. I did like this /abc/tej --version | grep "(?<=Version = .*?()\d+.\d+(?=.\d+-\d+))". but I didn't get any output

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900