Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Shell Script Required

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-01-2008   -   Original Discussion by ntgobinath
ntgobinath ntgobinath is offline
Registered User
 
Join Date: May 2008
Last Activity: 11 November 2011, 1:42 PM EST
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux Question Shell Script Required

I have following information in one file.

ObjID: 004ee4e4-0d92-71dd-1512-9887a1f10000
Address: 152.135.0.61
PingState: Ping Responding
----------------Management Address---------------------
++++++++++++++++Interface+++++++++++++++++++++
IFName: dall00r1.mis.amat.com[ 0 [ 2 ] ]
ObjID: 0155c646-0d92-71dd-1512-9887a1f10000
IFAlias: -
IFDescription: GigabitEthernet0/0
Status: Normal
IfIndex: 2
IfType: 6
AggregatedInterfaceObjID: -
Capability: isL2Connected isCDP
----------------Interface---------------------
++++++++++++++++Interface+++++++++++++++++++++
IFName: dall00r1.mis.amat.com[ 0 [ 1 ] ]
ObjID: 0bb25a50-0d92-71dd-1512-9887a1f10000
IFAlias: Dest:AT&T MPLS CLOUD Type: ISP T1 CID:
IFDescription: Serial0/1/0
Status: Normal
IfIndex: 1
IfType: 23
AggregatedInterfaceObjID: -
Capability: isCDP isMulticast
++++++++++++++++Address+++++++++++++++++++++

Requirement:

Now, Whenever it's matches '++++++++++++++++Interface+++++++++++++++++++++' then it should print next 5 lines in the output file.

Pls. anybody gives script for this requirement. I'm new to scripting. Pls. help me out.

Thanks,
Gobinathan.S
Sponsored Links
    #2  
Old Unix and Linux 05-01-2008   -   Original Discussion by ntgobinath
chappidi_pradee chappidi_pradee is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 1 May 2008, 10:42 PM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
hello try this one out,

hope this helps you

please paste this in a file and make it shell executable by chmod 755 and run it.

awk ' $0 ~ /\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+Interface\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+/ {
match_str="YES"; line_cnt=0; next; }
{
if((line_cnt < 5) && ( match_str=="YES"))
{
print $0;
line_cnt += 1;
}
else {
match_str="NO"; line_cnt=0; }
}' inputfile_name
Sponsored Links
    #3  
Old Unix and Linux 05-01-2008   -   Original Discussion by ntgobinath
rubin's Unix or Linux Image
rubin rubin is offline Forum Advisor  
Registered User
 
Join Date: Nov 2007
Last Activity: 22 September 2010, 4:35 PM EDT
Posts: 325
Thanks: 0
Thanked 2 Times in 2 Posts

Code:
awk '/^\++\+Interface\++\+$/{a=NR+1}
 NR==a,NR==a+4{ print }' input > output

    #4  
Old Unix and Linux 05-06-2008   -   Original Discussion by ntgobinath
ntgobinath ntgobinath is offline
Registered User
 
Join Date: May 2008
Last Activity: 11 November 2011, 1:42 PM EST
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks to Chappidi!!!

Thanks Chappidi...Your script worked well.Linux
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help required with shell script bala123 Shell Programming and Scripting 4 03-15-2012 04:46 AM
Shell script is required at1700 Shell Programming and Scripting 3 07-17-2011 11:05 PM
shell script required... venkatesht Shell Programming and Scripting 3 01-13-2009 06:00 AM
Shell Script Required? Pls. help me ntgobinath Shell Programming and Scripting 22 05-29-2008 08:09 AM
shell script required sethunath Linux 1 07-07-2007 06:04 AM



All times are GMT -4. The time now is 05:19 PM.