Reputation: 3893
I have an utility script, that displays an information about deployed java app. Here is an example output of this script:
Name: TestAPP
Version : SNAPSHOT
Type : ear, ejb, webservices, web
Source path : /G/bin/app/TESTAPP_LIVE_1.1.9.1.1.ear
Status : enabled
Is it possible to grep Version and source path values using grep command? Right now im able to do this using following command:
| grep Version
But it outputs the whole string (e.g. Version: Snapshot) when i am need only a values (e.g Snapshot to use in further script commands)
Upvotes: 0
Views: 221
Reputation: 10867
Here is a pure grep
solution.
Use the -P
option for regex mode, and -o
option for retrieving only what is matching.
grep -Po "(?<=^Version : ).*"
Here is what you would do for Source:
grep -Po "(?<=^Source : ).*"
It uses a postive lookbehind.
Upvotes: 2
Reputation: 7310
Here's a solution using awk
if you're interested:
grep Version | awk '{print $3}'
$3
means to print the third word from that line.
Note that:
$2
instead.Upvotes: 0