Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-29-2012, 11:20 PM   #1
Registered: Apr 2010
Posts: 82

Rep: Reputation: 1
need help fetching required information

I call a sh file it returns lot of information I wan to retrieve a part of it

Here is what I get
[ec2-user@domU-12-31-39-10-44-32 ~]$ /opt/aws/apitools/ec2/bin/ec2-describe-instances --filter "instance-id=i-8d28b5eb"
RESERVATION     r-61b4d103      424912172560    artms-web
INSTANCE        i-8d28b5eb      ami-e565ba8c       domU-12-31-39-10-44-32.compute-1.internal       running artms-default   0
                m1.large        2012-05-25T18:01:29+0000        us-east-1a      aki-88aa75e1                    monitoring-enabled   e
bs                                      paravirtual     xen             sg-e55aeb8d     default
BLOCKDEVICE     /dev/sda1       vol-84242deb    2012-05-25T18:01:57.000Z        true
BLOCKDEVICE     /dev/sdf        vol-04ffe76b    2012-05-25T18:01:57.000Z        false
TAG     instance        i-8d28b5eb      Name    stg-app/web-0
all I want from this is value of Name which is stg-app/web-0
also I want to check if the value of name which is stg-app/web-0 contains "stg"

please help me.
Old 05-30-2012, 01:44 AM   #2
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
That's easy, just pipe into awk:

/opt/aws/apitools/ec2/bin/ec2-describe-instances \
    --filter "instance-id=i-8d28b5eb" | \
    awk '/Name/ { print $NF }'
To check if it contains stg, just add another pipe to grep -c.

stg=$(/opt/aws/apitools/ec2/bin/ec2-describe-instances \
    --filter "instance-id=i-8d28b5eb" | \
    awk '/Name/ { print $NF }' | \
    grep -c 'stg')

if [ $stg -gt 0 ]; then
    echo "It contained stg."
    echo "No stg."

Last edited by jhwilliams; 05-30-2012 at 01:47 AM.
Old 05-30-2012, 01:57 AM   #3
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,757

Rep: Reputation: 7299Reputation: 7299Reputation: 7299Reputation: 7299Reputation: 7299Reputation: 7299Reputation: 7299Reputation: 7299Reputation: 7299Reputation: 7299Reputation: 7299
Originally Posted by jhwilliams View Post
To check if it contains stg, just add another pipe to grep -c.
Oh, no!
if you already caught that string you can check it in awk, do not use grep:
awk '/Name/ { print $NF; if ( index($NF, "stg") ) print "STG" }'
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
error fetching interface information: device not found jhelzunn Linux - Networking 9 08-09-2017 04:24 PM
eth0 :error fetching interface information sai_tejas Linux - Networking 2 06-05-2008 01:52 AM
: error fetching interface information: Device not found Beauford-2 Slackware 5 02-13-2008 09:28 AM
Fetching the distribution release information on AIX machine afrose_fathima AIX 3 05-16-2006 04:17 AM
error fetching interface information jw.pi Linux - Networking 2 06-22-2001 06:37 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:25 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration