Shell Script Required? Pls. help me


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script Required? Pls. help me
# 15  
Old 05-28-2008
Script is working flawlessly on my box although only one record is returned. I notice that you have a number of occurrences of:

----------------- NMInterface --------------
+++++++++++++++++ NMInterface ++++++++++++++

and not only

============ Interface Information ====================
+++++++++++++++++ NMInterface ++++++++++++++


Not the same record separator.

Which version of awk do you have?

$ awk --version
# 16  
Old 05-28-2008
Yes, But my requirement is,

Whenever the string matches "+++++++++++++++++ NMInterface ++++++++++++++" then It should print upcoming line of 3rd line, 8th line and 21st line. (No need to consider the above line in any of the text pattern)

I already have same kind of script that will print Whenever the string matches "+++++++++++++++++ Interface ++++++++++++++" it's printing next 5 lines.
#!/bin/sh
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; }
}' <Input_File>


Pls. guide me now.
Thanks,
Gobinathan.S
# 17  
Old 05-28-2008
Quote:
Originally Posted by ntgobinath
Yes, But my requirement is,

Whenever the string matches "+++++++++++++++++ NMInterface ++++++++++++++" then It should print upcoming line of 3rd line, 8th line and 21st line. (No need to consider the above line in any of the text pattern)
Right. Try this:

Code:
$ awk 'BEGIN {RS="\++ NMInterface";OFS=FS="\n";ORS="\n\n"} {print $4,$9,$22}' your.file

But in that case the 21th line doesn't always return what you expect:

Code:
EntityName:aust00m1.mis.amat.com[ 0 [ 255 ] ]
OverallStatus:Normal
IfName:AT9/1/0.145

EntityName:aust00m1.mis.amat.com[ 0 [ 256 ] ]
OverallStatus:Normal
Capability: 

EntityName:aust00m1.mis.amat.com[ 0 [ 257 ] ]
OverallStatus:Normal
IfName:AT9/1/0.315

EntityName:aust00m1.mis.amat.com[ 0 [ 258 ] ]
OverallStatus:Normal
Capability: 

EntityName:aust00m1.mis.amat.com[ 0 [ 259 ] ]
OverallStatus:Normal
IfName:AT9/1/0.325

Still have the same pbl with awk?
# 18  
Old 05-29-2008
Hi Ripat,

Thank you so much for your hard work on my requirement. I'm looking for an alternate way to achive my requirement. Because It's not giving proper info on 21st line.

I will get back on the forum after I find an alternate way to grep my info.

Thanks for your support, Thanks all

Gobinathan.S
# 19  
Old 05-29-2008
Don't give up! If the 3rd info is not always on the 21st line, there is a work around. Try this:
Code:
#!/bin/bash 
awk '
BEGIN {RS="\++ NMInterface";OFS=FS="\n";ORS="\n\n"}
{match($0, /IfName:[^\n]+/, out);print $4,$9,out[0]}' your.file

# 20  
Old 05-29-2008
Ripat,

How to run this file?

I'm using HP-UX 11.23

First I copied all those your commands to file 'int'
then executed,
Error:
# ./int
syntax error The source line is 3.
The error context is
{match($0, >>> /IfName:[^\n]+/, <<<
awk: The statement cannot be correctly parsed.
The source line is 3.


Then I changed to bash.
then executed,
ERROR:
# bash
# ./int
Segmentation fault (core dumped)

How to resolve this issue?

Thanks,
Gobinathan.S
# 21  
Old 05-29-2008
The third element of the match() function is a GNU awk extension. How about this:

Code:
#!/bin/bash 
awk '
BEGIN {RS="\++ NMInterface";OFS=FS="\n";ORS="\n\n"}
{print $4,$9,substr($0, match($0, /IfName:/), 18)}
' your.file

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