Omar Ahmad Omar Ahmad - 3 months ago 18
Linux Question

Extract some characters from a file using sed

I have a text file that contain some information that I need to extract, an example file is as follows:

"version": (2, 0, 0),
"location": "Node Editor",
"category": "Node",


I want to get the version info in the form 2.0.0. I tried doing it by sampling the line and then sampling the version numbers and then combine them, but it was messy. What is the best way to do this?

tso tso
Answer Source
sed -n 's/.*\"version\":[^(]*(\(.*\)).*/\1/p' __init__.py |sed 's/, /\./g'

output:

2.0.0