error in awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error in awk script
# 1  
Old 06-07-2004
error in awk script

could any one tell me the error in the script here...

it says

awk: syntax error near line 15
awk: bailing out near line 15


... the awk script is attached

#This awk script collects the undec neighbour info
#
BEGIN {
printf "SOURCE\tSECTOR\tPNPHASE\tLEVEL\t\REFERENCE\n"
}
/Primary/ {
srce=$4;
sector=$6;
reference=$10;
getline;
pnphase=$6;
level=$8/-2;

}

if (reference==no) then
/Ref: yes/ {
reference_pnoffset=$6;
else
reference_pnoffset="SAME";
endif

print srce"\t"sector"\t"pnphase"\t"level"\t"reference_pnoffset
}
# 2  
Old 06-08-2004
I think my previous post did not receive any reply as it needs more clarification...

My input file looks as attcahed

=======================================================================
Record: 24950188 Version: 2 Timestamp: Mon Jun 7 15:00:06 2004
Primary (Reporting) Cell: 30 Sector: 3 Carrier: 1 Ref: yes Event: 46988
Missing Pilot: Keep: 1 PN-Phase: 0x0191 Strength: 25
Secondary Sector Information:
Slot 1: Keep: 1 Pn_offset: 72 Strength: 26 Ref: no
=======================================================================
Record: 24950189 Version: 2 Timestamp: Mon Jun 7 15:00:06 2004
Primary (Reporting) Cell: 30 Sector: 3 Carrier: 2 Ref: no Event: 46989
Missing Pilot: Keep: 1 PN-Phase: 0x7456 Strength: 26
Secondary Sector Information:
Slot 1: Keep: 1 Pn_offset: 357 Strength: 28 Ref: yes
Slot 2: Keep: 1 Pn_offset: 393 Strength: 29 Ref: no
=======================================================================
Record: 24950190 Version: 2 Timestamp: Mon Jun 7 15:00:06 2004
Primary (Reporting) Cell: 30 Sector: 3 Carrier: 2 Ref: no Event: 46990
Missing Pilot: Keep: 1 PN-Phase: 0x7456 Strength: 25
Secondary Sector Information:
Slot 1: Keep: 1 Pn_offset: 357 Strength: 27 Ref: yes
Slot 2: Keep: 1 Pn_offset: 393 Strength: 30 Ref: no
=======================================================================
Record: 24950191 Version: 2 Timestamp: Mon Jun 7 15:00:06 2004
Primary (Reporting) Cell: 30 Sector: 3 Carrier: 2 Ref: no Event: 46991
Missing Pilot: Keep: 1 PN-Phase: 0x7456 Strength: 22
Secondary Sector Information:
Slot 1: Keep: 1 Pn_offset: 357 Strength: 27 Ref: yes
Slot 2: Keep: 1 Pn_offset: 393 Strength: 32 Ref: no
=======================================================================
...........................
what my code is attempting to do is.....

If in the second line of every record the Ref:no is set then i need to pick up the Pn_offset: value for the next line where Ref: yes is set.

Ref:no Ref:yes Pn_offset:



Now it 's alittle bit more clear i hope.....
# 3  
Old 06-09-2004
Hi, just looked at your code and thought about the logic.

if (reference==no) then

you might want to do it like this

if (reference=="no") then since you are comparing to a string.
Also, if I am not mistaken it only assigns value to reference if it finds Primary, else reference==null.....you might wanna review that.

Not sure if it works, but just giving my point of view Smilie
# 4  
Old 06-09-2004
This bit is all wrong....
Code:
if (reference==no) then
/Ref: yes/ {
reference_pnoffset=$6;
else 
reference_pnoffset="SAME";
endif

- if statements do not use "then" or "endif"
- you cannot use an if statement outside of an action
# 5  
Old 06-09-2004
i have tweaked it but still have some problem as ...

my o/p looks as follows... notice that the same event no is repaeted.. i do't want that..
pl help

SOURCE SECTOR PNPHASE LEVEL REFERENCE EVENTNO
66 3 0x79a8 -9 SAME 22424
66 3 0x79a8 -9 SAME 22424
66 3 0x79a8 -9 SAME 22424
66 3 0x79a8 -9 255 22424
66 3 0x79a8 -9 SAME 22424
66 3 0x79a8 -9 SAME 22424
66 2 0x79a8 -9 SAME 22429
66 2 0x79a8 -9 SAME 22429
66 2 0x79a8 -9 SAME 22429
66 2 0x79a8 -9 423 22429
66 2 0x79a8 -9 SAME 22429
66 2 0x79a8 -9 SAME 22429
66 2 0x79a8 -7.5 SAME 22430
66 2 0x79a8 -7.5 SAME 22430
66 2 0x79a8 -7.5 423 22430
66 2 0x79a8 -7.5 SAME 22430
66 2 0x79a8 -7.5 SAME 22430
66 2 0x79a8 -7.5 SAME 22430

.............

my code now looks as...
#This awk script collects the undec neighbour info
#
BEGIN {
printf "SOURCE\tSECTOR\tPNPHASE\tLEVEL\tREFERENCE\tEVENTNO\n"
}
/Primary/ {
srce=$4;
sector=$6;
reference=$10;
eventno=$12;
getline;
pnphase=$6;
level=$8/-2;
}
(reference=="yes") {
reference_pnoffset="SAME";
print srce"\t"sector"\t"pnphase"\t"level"\t"reference_pnoffset"\t"eventno
}
(reference==no) {
if ($0 ~ /Ref: yes/ )
reference_pnoffset=$6;
print srce"\t"sector"\t"pnphase"\t"level"\t"reference_pnoffset"\t"eventno
}


.....
# 6  
Old 06-09-2004
Even though I am still baffled by what is going on in this post, this seems to work for me, making some assumptions about what it is you are trying to achieve....

Code:
#This awk script collects the undec neighbour info
#
BEGIN { 
   printf "SOURCE\tSECTOR\tPNPHASE\tLEVEL\tREFERENCE\tEVENTNO\n"
   RS="\n===*\n"
}
{
   srce=$14;
   sector=$16;
   reference=$20;
   eventno=$22;
   pnphase=$28;
   level=$18/-2;
}
{ if (reference=="yes") {
      reference_pnoffset="SAME";
      print srce"\t"sector"\t"pnphase"\t"level"\t"reference_pnoffset"\t"eventno
  }
}
{ if (reference=="no") {
   if ($0 ~ /Ref: yes/ ) {
      reference_pnoffset=$39;
      print srce"\t"sector"\t"pnphase"\t"level"\t"reference_pnoffset"\t"eventno
    }
  }
}

Any good to you? You'll probably have to adjust some of the field numbers (e.g. $39) as it's hard to tell from your data file what information you're pulling out of it.

Cheers
ZB

Last edited by zazzybob; 06-09-2004 at 10:54 AM..
# 7  
Old 06-10-2004
thanks guys.. for ur look into...

I still have the problem...

zazzybob.... let me chart the flow of the code


1> Every record will be between two "=============" . This is pretty clear from the sample i posted.

2> If we have "Ref: yes" in the line which contains the pattern "Primary" , then we pick up the field "PN-phase: ??????? " from the line next to it( that contains "Primary") and also

3> In case we have "Ref: no" in the line which contains the pattern "Primary" , then we pick up the field "Pn_offset: " from the immediate next line that has "Ref: yes" .

e.g
=======================================================================
Record: 42759421 Version: 2 Timestamp: Wed Jun 9 15:00:09 2004
Primary (Reporting) Cell: 25 Sector: 2 Carrier: 2 Ref: no Event: 20984
Missing Pilot: Keep: 1 PN-Phase: 0x50fc Strength: 29
Secondary Sector Information:
Slot 1: Keep: 1 Pn_offset: 84 Strength: 27 Ref: no
Slot 2: Keep: 1 Pn_offset: 480 Strength: 29 Ref: yes
=======================================================================
in this case the o/p will look like
SOURCE SECTOR PNPHASE LEVEL REFERENCE EVENTNO
25 2 0x50fc -14.5 480 20984


Whereas as in this case
=======================================================================
Record: 42759422 Version: 2 Timestamp: Wed Jun 9 15:00:10 2004
Primary (Reporting) Cell: 14 Sector: 2 Carrier: 2 Ref: yes Event: 12583
Missing Pilot: Keep: 1 PN-Phase: 0x5b88 Strength: 26
Secondary Sector Information:
Slot 1: Keep: 1 Pn_offset: 381 Strength: 24 Ref: no
Slot 2: Keep: 1 Pn_offset: 54 Strength: 29 Ref: no
=======================================================================

the o/p will be

SOURCE SECTOR PNPHASE LEVEL REFERENCE EVENTNO
14 2 0x5b88 -13 SAME 12583

....


PLS HELP
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script with awk command ERROR

Hello im new here... Im trying to read file and create folders from words in it but i get this for loop error awk : line 3 : syntax error at or near for my code is.. #!/bin/bash begin for (( i=1;i<=5;i++)); do awk -v i=$i $0 { print $i } mkdir $i done {print $i} end {} i have... (7 Replies)
Discussion started by: boxstep
7 Replies

2. Shell Programming and Scripting

awk error in script

Hello Team, I am using below awk code in the script ssh -o ConnectTimeout=15 -n -l USER SERVER awk -F'\;' '{ if ( $3 == '-' && $1 ~ // ) print }' *20130706* but its giving error as awk: syntax error near line 1 awk: illegal statement near line 1 Please help. ... (6 Replies)
Discussion started by: skhichi
6 Replies

3. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

4. Shell Programming and Scripting

Help with awk script (syntax error in regular expression)

I've found this script which seems very promising to solve my issue: To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem. The passwords may or may not be contained within quotes, single quotes, etc. #!/bin/bash... (4 Replies)
Discussion started by: spacegoose
4 Replies

5. Shell Programming and Scripting

Help to Iron out Script Awk Error

STRING1=JAVA CONTENTS=$(awk -v x="$STRING1" '$0 ~ x { print ll } { ll = $0}' $LOGFILE | tail -150 | egrep "Jan |Feb |Mar |Apr |May |Jun |Jul |Aug |Sep |Oct |Nov |Dec " | cut -c6-1000 | tail -1) When I run the above from a script, i get the following errors: syntax error at -e line 1,... (1 Reply)
Discussion started by: SkySmart
1 Replies

6. Shell Programming and Scripting

Execution error with awk script

Hi, I run an awk script and I got the error attached below: here are the lines that the compiler point to as an error: duration = timeEnd1-timeBegin1; print "Transmission: type of traffic " flow1 ; print “ - Total transmitted bits = ” totalBits1 ” bits”; print “ - duration = ”... (2 Replies)
Discussion started by: ENG_MOHD
2 Replies

7. Shell Programming and Scripting

awk script Error in Sun Solaris

Hi Friends, the below script has been through the errors in sun solaris. awk '/%s/{f=0 ;n++; print >(file="OUT_" n); close("OUT_" n-1)} f{ print > file}; /%s/{f=1}' $BASE_DIR/concat.TXT awk: syntax error near line 1 awk: bailing out near line 1 And ls $MERGE_DIR/*.R | awk ' { ... (2 Replies)
Discussion started by: krbala1985
2 Replies

8. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

9. Shell Programming and Scripting

awk script error

I am getting this error: awk: cmd. line:1: BEGIN {print "Userid Shell" } awk: cmd. line:1: ^ syntax errorBased on this script: #!/bin/bash awk -F":" \ '{ BEGIN {print "Userid Shell" } loginname=$1 optionalpass=$2 numericuserid=$3 numericgroupid=$4 username=$5 userhomedir=$6... (1 Reply)
Discussion started by: holocene
1 Replies

10. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies
Login or Register to Ask a Question