AWK syntax help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK syntax help
# 15  
Old 04-21-2010
i dont think i understood that correctly. Please check my code to see if this is what you meant. by the way, thank you very much for helping me. i was out of options.

Code:
 file=../data/globallyIgnoredTc.dat
   #set -A ignore `grep -v "#" ${file} | tr '[A-Z]' '[a-z]' `
   set -A ignore `grep -v "#" ${file} `
   ign=${ignore[@]}
       #################################################

  endMarker="NSC Termination Event Details:"

  if [ ! -f $4 ] ; then
    echo "No $4 file found.  Perhaps testMgr is still running?"

  else

    # Subtract out a little from the start time.  Otherwise we miss
    # crashes because of the controller clocks being off by a few seconds.
    #dateFilter $4 $(( $2 - 10 )) $3 > $con

    # BGL -- analyze all of the consoles.  Autotest does the trimming now.
    
	if [ $(print - "${ignore[@]}" | grep -c "$2") -gt 0 ] ; 
		then 
			status="found $2 in array ignore[]" 
		else 
			status="did not find $2 in array ignore[]" 
	fi



    termReport.pl < $4 | dos2ux |  head -2000 | awk '
    
    BEGIN { foundTermEvent=0;
            endMarker="'"${endMarker}"'"; }

    {
      if ( (substr($0, 1, length(endMarker)) == endMarker) ||
           (substr($0, 1, 39) == "'${SBINDIR}'/termReport.pl: ") )
      {
        if (foundTermEvent == 1)
        {
          print "";
          foundTermEvent=0;
        }
      }
      ##############################################################################
       if (foundTermEvent == 1)
       {
				  if (status == "found $2 in array ignore[]")
				  {
                  foundTermEvent = 0;
				  }

                  else
                  {
				  print;
				  }
   

       }
####################################################################
      if (substr($0, 1, 18) == "Termination Event:")
      {
        foundTermEvent=1;
      }
	  }'
	  fi
	  }

# 16  
Old 04-21-2010
You are right. Did the script run fine now?
# 17  
Old 04-21-2010
i dont get any errors now. but it is not doing what it supposed to do. it seems like it never finds a match when comparing $2 to the array. in reality, there are matches and it should find it.

could this happen because we have if statement before i have any data for $2?

---------- Post updated at 01:04 PM ---------- Previous update was at 12:46 PM ----------

i verified this, it doesnt have correct values for $2 by the time if statement excuted. Because $2 values arent going to be ready till AWK statemnet has been excuted.
# 18  
Old 04-21-2010
Is $2 second argument to your script or Second field in your input from termReport.pl?
# 19  
Old 04-21-2010
$2 is comming from termReport.pl out put. it is the 2nd field.
# 20  
Old 04-21-2010
Create another script to check whether second field exists in ignore array

checkSecondFldInArray
Code:
file="path_to_file"
set -A ignore `grep -v "#" ${file} ` 

if [ $(print - "${ignore[@]}" | grep -c "$1") -gt 0 ] ; 
then 
	echo "found" 
else 
	echo "not found" 
fi

Change awk code to call above script
Code:
if (foundTermEvent == 1) 
{ 
	"checkSecondFldInArray " $2 | getline status
	if (status == "found") { foundTermEvent = 0; }

# 21  
Old 04-21-2010
array "ignore" reads a data file. data file only has a one field and i verfied that ignore arrray loads with correct info as follows.
ignore[0]=erf45
ignore[1]=34fgh
.
.
ignore[n]=rtghf

$2 comes from termReport.pl output. It seems like $2 doesnt get read before we use it. Does this make sense?

in the if statement, i tried to print the value for $2 so i can see if it get correct value. but it does not. please see the code below




Code:
. lib.ksh

if [ _$1  = _-all ] ; then
  all=1
fi  

failures=/tmp/failures.tmp
failLines=/tmp/failLines.tmp
utilFailLines=/tmp/utilFailLines.tmp
miscompareLines=/tmp/miscompareLines.tmp
con=/tmp/con.tmp
failInfo=/tmp/failInfo.tmp

function analyzeConsole
{
  # First, cut the console data down to just the part that printed
  # out during that test.  
  # Then run it through termReport.pl.
  # Then get the interesting parts of that.
  #################################################
     # Reading from globallyIgnoredTc list and setting up an array & converting upper case to lower case

   file=../data/globallyIgnoredTc.dat
   #set -A ignore `grep -v "#" ${file} | tr '[A-Z]' '[a-z]' `
   set -A ignore `grep -v "#" ${file} `

#      i=0
#      while [[ $i -lt ${#ignore[*]} ]] ; do
#      echo " ignore[$i] = ${ignore[$i]}"
#      let i=$i+1
#      done
       #################################################

  endMarker="NSC Termination Event Details:"

  if [ ! -f $4 ] ; then
    echo "No $4 file found.  Perhaps testMgr is still running?"

  else

    # Subtract out a little from the start time.  Otherwise we miss 
    # crashes because of the controller clocks being off by a few seconds.
    #dateFilter $4 $(( $2 - 10 )) $3 > $con

    # BGL -- analyze all of the consoles.  Autotest does the trimming now.
    if [ $(print - "{ignore[@]}" | grep -c "$2") -gt 0 ] ;
        then
        echo "found"
	echo " ############## "
        echo " NAME = $2 "
	echo " ############## "
    else   
        echo "not found"
	echo " ***************** "
	echo " NAME = $2 "
	echo " ***************** "
    fi

#    termReport.pl < $4 | dos2ux |  head -2000 | awk -v ign="${ign}" -v searchStr="$2" '
    termReport.pl < $4 | dos2ux |  head -2000 | awk '
    BEGIN { foundTermEvent=0;
            endMarker="'"${endMarker}"'"; }

    {
      if ( (substr($0, 1, length(endMarker)) == endMarker) || 
           (substr($0, 1, 39) == "'${SBINDIR}'/termReport.pl: ") )
      {
        if (foundTermEvent == 1)
        {
          print "";
          foundTermEvent=0;
        }
      }
      ##############################################################################
       if (foundTermEvent == 1)
       {
                 if ( status == "found" )
                 {
#		 print " ################## "
	         foundTermEvent = 0;
                 }

                 else
                 {
#                 print " ***************** "
                 print;
                 }

       
       }
####################################################################
      if (substr($0, 1, 18) == "Termination Event:")
      {
        foundTermEvent=1;
      }
    }'

  fi
}


function analyzeFailure
{

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: syntax error

awk -F, ' NR>1 { BEGIN{ chr=$2 } END{ for (k in chr) {print k} } } ' $gene_file I've a really simple code. I want to store gene name and it's chromosome and in the end print them. I'm skipping line one as it contains headers. But I don't know why I get error as: (2 Replies)
Discussion started by: genome
2 Replies

2. Shell Programming and Scripting

Help with the awk syntax

Hello Experts: While writing a script to help one of the posts on here, I end up writing a wrong one. I am very much eager to know how this can be corrected. Aim was to not print specified columns - lets say out of 100 fields, need to print all but 5th, 10th, 15th columns. Someone already... (13 Replies)
Discussion started by: juzz4fun
13 Replies

3. Shell Programming and Scripting

Syntax Problem with awk

Hello, I have perl script,which take some part of data in the file. the below command works fine in normal cmd prompt. `awk '/CDI/ && // && !/Result for/ {print $3 $5 > "final.txt"}' datalist.txt`; `nawk -F"" '{print $2}' finalcdi.txt`; But not working. Please use code tags, thanks. (5 Replies)
Discussion started by: rasingraj
5 Replies

4. Shell Programming and Scripting

AWK Function syntax

Hi, I would like to know what is the correct syntax to perform a function in awk. Although I have seen several examples, not get it to work, this is what I'm trying: #!/bin/bash awk function multi (number) { return number * 3 } print multi (4)Thanks (2 Replies)
Discussion started by: Godie
2 Replies

5. Shell Programming and Scripting

awk syntax

Hi I have a bash file which will split a big file to many small files. But I got a syntax error.H="$(head -1 CCC.tped)" awk 'print $0 > $1 ".tped"' CCC.tped for f in $(ls *.tped); do echo "$H\n" "$(cat $f)" >$f; done And -bash-4.1$ bash split awk: print $0 > $1".tped" awk: ^ syntax error... (3 Replies)
Discussion started by: zhshqzyc
3 Replies

6. AIX

Help with syntax using AWK

I have a file which is comma separated and has quotes. I can use this command and awk -F"," '{ if ($4=="01" print $0 }' test.txt But this doesn't fetch me the data.since it has quotes. If the data has no quotes,the above command works fine. In Unix you can skip quote \" but this doesn't work.... (7 Replies)
Discussion started by: ganesnar
7 Replies

7. UNIX for Dummies Questions & Answers

awk syntax

Little bit confusing while using awk :confused::confused: In Sed while pattern search we can use "(double quotes) i mean $a=hello $cat file.txt |sed -n "/$a/p"this thing work fine But if i use it in awk it's not working How could i do the substitution of pattern by a variables and the... (1 Reply)
Discussion started by: posix
1 Replies

8. Shell Programming and Scripting

AWK syntax

Hi I am trying to understand AWK syntax so I tried this command which gives me the home directory of root awk 'BEGIN { FS = ":"} {if ($1 == "root") print $6 }' /etc/passwd I would know what are the following commands doing. The first one prints all /etc/passwd, second prints nothing. ... (4 Replies)
Discussion started by: wakatana
4 Replies

9. Shell Programming and Scripting

awk syntax help

I don't get correct output when I run this command line: nmap -sP failedhost.com | grep -i failed | awk -F '{print $6}' I basically want it to return 'failedhost.com' but its just showing the output of the nmap scan. (8 Replies)
Discussion started by: streetfighter2
8 Replies

10. Shell Programming and Scripting

Help with Awk Syntax

I have written many awk commands which go in multiple lines. I have this confusion many times. Some time they work if i dont terminate them with "\" but some time error. Some time in "if" statements between if and else if i dont use ";" it gives error but sometimes it doesnt. The below... (4 Replies)
Discussion started by: pinnacle
4 Replies
Login or Register to Ask a Question