![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell Script Required? Pls. help me | ntgobinath | Shell Programming and Scripting | 22 | 05-29-2008 04:09 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
Code:
awk '/^\++\+Interface\++\+$/{a=NR+1}
NR==a,NR==a+4{ print }' input > output
|
|
#4
|
|||
|
|||
|
Thanks to Chappidi!!!
Thanks Chappidi...Your script worked well.
|
|||
| Google The UNIX and Linux Forums |