I'm a total n00b when it comes to using sed
and can't quite figure this out...
I've got the following data being output by a command line tool:
ruby:
interpreter: "ruby"
version: "1.8.6"
date: "2010-02-04"
platform: "i386-mingw32"
patchlevel: "398"
full_version: "ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32]"
homes:
gem: ""
ruby: "C:\ruby\ruby-1.8.6-p398-i386-mingw32"
binaries:
ruby: "C:\ruby\ruby-1.8.6-p398-i386-mingw32\bin"
irb: "C:\ruby\ruby-1.8.6-p398-i386-mingw32\bin\irb.bat"
gem: "C:\ruby\ruby-1.8.6-p398-i386-mingw32\bin\gem.bat"
rake: ""
environment:
GEM_HOME: ""
HOME: "c:/Users/derick"
IRBRC: ""
RUBYOPT: ""
file associations:
.rb:
.rbw:
I want to use sed to extract the values from interpreter
and version
only, and have them returned as "interpreter-version".
The best I could come up with so far is to use grep to return the entire version line:
pik info | grep -e '^version:.*'
but that returns too much info from the version line, and doesn't include the interpreter (obviously).
How can i use sed
to extract only the bits of information that i want, so that i get a result of ruby-1.8.6
?
... or grep, or awk, or any other command line tool to get the info i want...
FWIW: i'm not using RVM because this is a windows machine using MinGW32... i'm using Pik, which is similar to RVM but made for windows.
A lot of you are working hard to deal with the quotes. Let awk do it:
pik info | awk -F '"' '
/^interpreter:/ {interp = $2}
/^version:/ {ver = $2}
interp && ver {print interp "-" ver; exit}
'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With