0

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)

3
  • 3
    grep Version | cut -d ':' -f 2 Commented Apr 26, 2013 at 12:50
  • posted as answer please like if it works Commented Apr 26, 2013 at 13:00
  • You can also use awk: |grep Version|awk '{$print $3}' (I'm using $3 and not $2 because there is a space between ':' and the other words) Commented Apr 26, 2013 at 13:02

3 Answers 3

2
grep Version | cut -d ':' -f 2 
Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0

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:

  1. This displays one word only
  2. This assumes you have spaces between the colon (and therefore the version is actually the third "word"). If you don't, use $2 instead.

Comments

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.