Sponsored Content
Top Forums Shell Programming and Scripting AWK help: how to compare array elements against a variable Post 302414312 by usustarr on Monday 19th of April 2010 09:12:35 PM
Old 04-19-2010
AWK help: how to compare array elements against a variable

i have an array call ignore. it is set up
ignore[0]=34th56
ignore[1]=re45ty
ignore[2]=rt45yu
.
.
ignore[n]=rthg34

n is a variable. I have another variable that i read from a different file. It is $2 and it is working the way i expect. array ignore read and print correct values.

in the below if statement (2nd if statement where i use array ignore), i need to do following, if "$2" == 34th56 || "$2" == re45ty || .... "$2" == rt45yu .i dont want to do a while or for loop, because it is printing lots of junk that i dont want. Can any one help me with this please? Smilie



Code:
 
#! /usr/bin/ksh
# $2 is a variable and it is working the way i expect
# array ignore read and print correct values and it is working fine too
# in the if statement, i need to do following, if "$2" == ignore[0] || "$2" == ignore[1] || .... "$2" == ignore[n] 
#  { print "  " 
#   foundTermEvent = 0;
#   } 
#  else  {
#   print;
#   print " FOUND A BADTC  "  }

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

 if (foundTermEvent == 1)
       {
          if ( "$2" in ignore )  
          {
      
                print " DIDNT FIND BAD TC "
        #       { print $1 }
        #       { print $2 }
                foundTermEvent = 0;
       
          }
            else
            {
            print;
            print " FOUND A BADTC  "
        #    { print $1 }
           { print $2 }
            print " ########################## "
           }
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Accessing single elements of a awk array in END

How do I access one of the indices in array tst with the code below? tst=sprintf("%5.2f",Car / 12) When I scan thru the array with for ( i in tst ) { print i,tst } I get the output of: vec-7 144 But when I try this in the END print tst It looks like it's not set. What am... (6 Replies)
Discussion started by: timj123
6 Replies

2. Shell Programming and Scripting

compare a variable against array elements

hi everyone - i have a bash script that does, in broad terms, the following: given a file containing a list of email accounts, for every account, do , then move on to the next account. pretty simple, and all that stuff works fine. thing is, there's a very good change that any account... (2 Replies)
Discussion started by: fearboy
2 Replies

3. Shell Programming and Scripting

awk - array elements as condition

Hi, can I use array elements ( all ) in conditional statements? the problem is ,the total number of elements is not known. e.g A is an array with elements - 1,2,3 now if i want to test if the 1 st field of input record is either 1,2 or 3, i can do something like this if ( $1 ~... (1 Reply)
Discussion started by: shellwell
1 Replies

4. Shell Programming and Scripting

AWK help. how to compare a variable with a data array in AWK?

Hi all, i have a data array as follows. array=ertfgj2345 array=456ttygkd . . . array=errdjt3235 so number or elements in the array can varies depending on how big the data input is. now i have a variable, and it is $1 (there are $2, $3 and so on, i am only interested in $1). ... (9 Replies)
Discussion started by: usustarr
9 Replies

5. Shell Programming and Scripting

printing array elements inside AWK

i just want to dump my array and see if it contains the values i am expecting. It should print as follows, ignore=345fht ignore=rthfg56 . . . ignore=49568g Here is the code. Is this even possible to do? please help termReport.pl < $4 | dos2ux | head -2000 | awk ' BEGIN... (0 Replies)
Discussion started by: usustarr
0 Replies

6. Shell Programming and Scripting

Match elements in an AWK multi-dimensional array

Hello, I have two files in the following format; file1: A B C D E F G H I J K L file2: 1 2 3 4 5 6 7 8 9 10 11 12 I have read them both in to multi-dimensional arrays. I need a file that has column 2 of the first file printed out for each column 3 of the second file ie... ... (3 Replies)
Discussion started by: cold_Que
3 Replies

7. Shell Programming and Scripting

awk, associative array, compare files

i have a file like this < '393200103052';'H3G';'20081204' < '393200103059';'TIM';'20110111' < '393200103061';'TIM';'20060206' < '393200103064';'OPI';'20110623' > '393200103052';'HKG';'20081204' > '393200103056';'TIM';'20110111' > '393200103088';'TIM';'20060206' Now i have to generate a file... (9 Replies)
Discussion started by: shruthi123
9 Replies

8. Shell Programming and Scripting

Awk: Append new elements to an array

Hi all, I'm dealing with a bash script to merge the elements of a set of files and counting how many times each element is present. The last field is the file name. Sample files: head -5 *.tab==> 3J373_P15Ac1y2_01_LS.tab <== chr1 1956362 1956362 G A hom ... (7 Replies)
Discussion started by: lsantome
7 Replies

9. Shell Programming and Scripting

Help reading the array and sum of the array elements

Hi All, need help with reading the array and sum of the array elements. given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input Format The first line of the input consists of an... (1 Reply)
Discussion started by: nishantrefound
1 Replies

10. Shell Programming and Scripting

Compare multiple arrays elements using awk

I need your help to discover missing elements for each box. In theory each box should have 4 items: ITEM01, ITEM02, ITEM08, and ITEM10. Some boxes either have a missing item (BOX02 ITEM08) or might have da duplicate item (BOX03 ITEM02) and missing another one (BOX03 ITEM01). file01.txt ... (2 Replies)
Discussion started by: alex2005
2 Replies
ckport(1)						   System User's Manual: ckport 						 ckport(1)

NAME
ckport - portability analysis and security checking tool SYNOPSIS
ckport [OPTIONS]... file [file,...] DESCRIPTION
ckport is a tool to check already compiled binaries and libraries for porting and security problems. It uses objdump to read the binaries and analysis call and jump functions. This package is architecture independent and can be used on non-host architecture binaries if a objdump tool for the target architecture is installed. OPTIONS
--help -h Show this help. -- End of options, only filenames follow. --mode MODE Sets mode of operation. --db DBFILE Load database DBFILE. --db-dir DBDIR Load databases from directory DBDIR. --edit-vim Show vim command pointing to location of problem. --conf KEY=VAL Set config key KEY to value VAL. --warn-mode MODE Set mode for printing of warnings. --warn PT Warn about problems of type PT. --nowarn PT Ignore warnings about problems of type PT. --nowarns Disable all warnings. --nosummery Disable summery. --summery Enable summery. --summery-on-warn Only print summery if warnings has been found. --noheader Disable printing of headers. --header Enable printing of headers. --nofile-header Disable printing of headers for each file (operant). --file-header Enable printing of headers for each file (operant). --ignore PATTERN Ignore symbols matching this Perl regex pattern. --ignore-symbol SYMBOL Ignore symbol SYMBOL. --ignore-target TARGET Ignore warnings for target TARGET. --print-mode MODE Set mode of symbol printing to MODE. --print-unknown Print unknown symbols found. --print-unknown-defined Print list of unknown but defined (internal) symbols. --print-unused Print list of defined (internal) but unused symbols. --print-known Print list of known symbols. --print-pt Print list of known problem types. SEE ALSO
objdump(1). ckport April 2011 ckport(1)
All times are GMT -4. The time now is 10:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy