LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-30-2012, 12:20 AM   #1
fachhoch@gmail.com
Member
 
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
Code:
[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    ec2-23-22-144-254.compute-1.amazonaws.com       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      23.22.144.254   10.198.71.192   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, 02:44 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

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

Code:
/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.

Code:
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."
else
    echo "No stg."
fi

Last edited by jhwilliams; 05-30-2012 at 02:47 AM.
 
Old 05-30-2012, 02:57 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,904

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
Quote:
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:
Code:
awk '/Name/ { print $NF; if ( index($NF, "stg") ) print "STG" }'
 
1 members found this post helpful.
  


Reply


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 05:24 PM
eth0 :error fetching interface information sai_tejas Linux - Networking 2 06-05-2008 02:52 AM
: error fetching interface information: Device not found Beauford-2 Slackware 5 02-13-2008 10:28 AM
Fetching the distribution release information on AIX machine afrose_fathima AIX 3 05-16-2006 05:17 AM
error fetching interface information jw.pi Linux - Networking 2 06-22-2001 07:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:38 AM.

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