Shell Script Required? Pls. help me


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script Required? Pls. help me
# 1  
Old 05-28-2008
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  
Old 05-28-2008
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  
Old 05-28-2008
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  
Old 05-28-2008
Anyother script or Solution that will help me?
# 5  
Old 05-28-2008
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  
Old 05-28-2008
Error again

#Interface.sh < aust00m1
Memory fault(coredump)
# 7  
Old 05-28-2008
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 :

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script with following awk command pls help

Hi I want to create a shell script with the following awk command & also get the filenames in output. awk '/<catetcsecuretty0>/ {p=1} /<catvarlogmessages0>/ {p=0} p' *.xml As there will be multiple outputs related to many xml files I cannot identify which output belongs to which file ... (5 Replies)
Discussion started by: sharp488
5 Replies

2. Shell Programming and Scripting

Need help with first shell script pls.

Hi, I'm trying to extract information from one file to update another one and am a bit stuck. the first file is made up of tags e.g. <item>a@b.com</item> jksdhfjkdsh sldkjfds l klsjdf <item> c@d.com </item> what i'd like to do is extract the email addresses between these tags,... (6 Replies)
Discussion started by: newb1000
6 Replies

3. Shell Programming and Scripting

Error in Shell Script - Can anyone help Pls

Please find my shell script below ------------------------------------- #!/usr/bin/ksh ORAUSER=$1 P_REQUEST_ID=$4 current_time=`date +%m%d%y.%H%M%S` echo "Process started at `date +%m/%d/%y.%H:%M:%S`" #Intialize Variables export SHLIB_PATH=/usr/local/lib ext=".pdf" ps_ext=".ps"... (4 Replies)
Discussion started by: uuuunnnn
4 Replies

4. Shell Programming and Scripting

shell script, pls help

# for i in `cat oo`;do ls -ld $i;done ls: /var/tmp/i: No such file or directory ls: i: No such file or directory ls: /var/tmp/ii: No such file or directory ls: i: No such file or directory ls: /var/tmp/iii: No such file or directory ls: i: No such file or directory ls: /var/tmp/iiii: No such... (2 Replies)
Discussion started by: cpttak
2 Replies

5. Shell Programming and Scripting

Script changes required...Pls. help me!!

Hi All, I'm giving input of four variable. I'm using this script for network field, so I'm defining the example on the same way. Example Input: $1 =ind00m1 $2=Gi1/1 $3=10.0.0.1 $4=Connectivity from 1 to 2 Applies to following line: object=$2 msg_grp=SNMP node=$1 msg_text="IF Down $2 $3... (2 Replies)
Discussion started by: ntgobinath
2 Replies

6. Shell Programming and Scripting

Shell Script Requirements pls

Moderators note: This user has been banned for persistent rule breaking despite being warned that this would be the result. (0 Replies)
Discussion started by: tt1ect
0 Replies

7. Shell Programming and Scripting

Unix shell script couldn't be executed. Pls help!

I have wrriten a script to call sql script to do some work in database. However, the script couldn't be executed. The only information was: ksh: ./updt_attrib.ksh cannot execute. Please help me to identify where the problem is. I post script here for your reference. Thanks a lot. #!/bin/ksh ... (8 Replies)
Discussion started by: duke0001
8 Replies

8. Shell Programming and Scripting

Passing value from shell script to .pls file

I have a shell script which takes at the command prompt options like ss1.sh -F SCOTT -T JOHN F- From User T- To User I want to pass the From User(SCOTT) Value to another script ss2.pls (This script runs a PL/SQL Program). Depending on the FromUser value in the ss1.sh script i have to... (4 Replies)
Discussion started by: dreams5617
4 Replies
Login or Register to Ask a Question