The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 01:04 PM
Shell Script Required! vats Shell Programming and Scripting 3 08-28-2007 02:29 AM
shell script required sethunath Linux 1 07-07-2007 05:04 AM
shell script required sethunath Shell Programming and Scripting 4 07-06-2007 03:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-28-2008
ntgobinath ntgobinath is offline
Registered User
  
 

Join Date: May 2008
Posts: 38
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
  #2 (permalink)  
Old 05-28-2008
ranton ranton is offline
Registered User
  
 

Join Date: May 2008
Location: Alabaster, AL
Posts: 6
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
  #3 (permalink)  
Old 05-28-2008
ntgobinath ntgobinath is offline
Registered User
  
 

Join Date: May 2008
Posts: 38
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
  #4 (permalink)  
Old 05-28-2008
ntgobinath ntgobinath is offline
Registered User
  
 

Join Date: May 2008
Posts: 38
Anyother script or Solution that will help me?
  #5 (permalink)  
Old 05-28-2008
ranton ranton is offline
Registered User
  
 

Join Date: May 2008
Location: Alabaster, AL
Posts: 6
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.
  #6 (permalink)  
Old 05-28-2008
ntgobinath ntgobinath is offline
Registered User
  
 

Join Date: May 2008
Posts: 38
Error again

#Interface.sh < aust00m1
Memory fault(coredump)
  #7 (permalink)  
Old 05-28-2008
ripat ripat is online now Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
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 :
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0