The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Script Required ntgobinath Shell Programming and Scripting 3 05-06-2008 10:04 AM
Shell Script Required! vats Shell Programming and Scripting 3 08-27-2007 11:29 PM
shell script required sethunath Linux 1 07-07-2007 02:04 AM
shell script required sethunath Shell Programming and Scripting 4 07-06-2007 12:39 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: May 2008
Posts: 26
Shell Script Required? Pls. help me

Hi All,

I have Information in the file like,

============ Interface Information ====================
+++++++++++++++++ NMInterface ++++++++++++++
ObjID:251c55a2-2257-71dd-0f68-9887a1f10000
NNMObjID:82857
EntityName:aust00m1.mis.amat.com[ 0 [ 161 ] ]
Description:ATM9/0/0-atm layer
Discovered in Zone:0
EntityType:Interface
IPLevel:4
OverallStatus:NotMon
OADId:0
StatusChangeTime:0
CreateTime:1210839357
ChangeTime:1210839357
Containment Parent:aust00m1.mis.amat.com(1d5ebb70-2257-71dd-0f68-9887a1f10000)
==========Interface Property===============
VPI:0
VCI:0
BoardNo:-
PortNum:0
AuxPortNum:0
IfIndex:161
IfName:AT9/0/0
IfAlias:-
IfType:37
PhysicalAddress:-
L2DomainID:-1
IfOperStatus:2
IfAdminStatus:2
VlanPortType:2001689792
isDiscoContrivedIF:0
IfSpeed:0
IF Capability :


Requirement:

Whenever the string matches "+++++++++++++++++ NMInterface ++++++++++++++" then It should print followed of 3rd line, 8th line and 21st line.

Example result:

EntityName:aust00m1.mis.amat.com[ 0 [ 161 ] ] (3rd line)
OverallStatus:NotMon (8th line)
IfName:AT9/0/0 (21st line)


If anystring match again it should do the same operation.

Thanks in Advance,
Gobinathan.S
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: May 2008
Location: Alabaster, AL
Posts: 5
Re: Shell Script Required? Pls. help me

Try this, I am sure there are shorter ways to do this, but this one works fine and is easy to follow

Code:
#!/bin/sh

declare -i lineno
declare -i hadmatch=0
while read line; do
    #echo $line
    #match=`echo $line | grep 'NMInterface'`
    match=`echo $line | grep '^+*\s*NMInterface\s*+*$'`
    if [ ! -z "$match" ]; then
        echo "$match"
        lineno=0
        hadmatch=1
    fi  
    if [ $hadmatch != 0 ]; then
        #echo "line $lineno: $line"

        if [ $lineno == 3 ]; then
            echo $line
        elif [ $lineno == 8 ]; then
            echo $line
        elif [ $lineno == 21 ]; then
            echo $line
        fi
        lineno=$lineno+1
    fi  
done
Reply With Quote
  #3 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: May 2008
Posts: 26
I'm getting the following error:
./Interface.sh[3]: declare: not found.
./Interface.sh[4]: declare: not found.

Also, Tell me How to insert the Input file?

Thanks,
Gobinathan.S
Reply With Quote
  #4 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: May 2008
Posts: 26
Anyother script or Solution that will help me?
Reply With Quote
  #5 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: May 2008
Location: Alabaster, AL
Posts: 5
declare not found

Sorry, first line needs to be #!/bin/bash instead. of #!/bin/sh

/bin/sh is a link on my linux system to /bin/bash so I failed to notice I had put bash specific syntax in there.

Just pipe the input file into the script, like so

script < inputfile

Or if you want to pass it on the command line add something like this on the line immediately before the while like so:
Code:
cat $1 |
while read line; do
Which will cause it to read from the file passed as the first argument instead of from the standard input.
Reply With Quote
  #6 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: May 2008
Posts: 26
Error again

#Interface.sh < aust00m1
Memory fault(coredump)
Reply With Quote
  #7 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
I imagine that your file contains more than one "record". Is there a separation between records. Like a blank line?

Code:
============ Interface Information ====================
+++++++++++++++++ NMInterface ++++++++++++++
ObjID:251c55a2-2257-71dd-0f68-9887a1f10000
...
==========Interface Property===============
...
VlanPortType:2001689792
isDiscoContrivedIF:0
IfSpeed:0
IF Capability : 

============ Interface Information ====================
+++++++++++++++++ NMInterface ++++++++++++++
ObjID:251c55a2-2257-71dd-0f68-9887a1f10000
...
==========Interface Property===============
...
VlanPortType:2001689792
isDiscoContrivedIF:0
IfSpeed:0
IF Capability : 

============ Interface Information ====================
+++++++++++++++++ NMInterface ++++++++++++++
ObjID:251c55a2-2257-71dd-0f68-9887a1f10000
...
==========Interface Property===============
...
VlanPortType:2001689792
isDiscoContrivedIF:0
IfSpeed:0
IF Capability :
Reply With Quote
Google UNIX.COM
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0