printing array elements inside AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting printing array elements inside AWK
# 1  
Old 04-20-2010
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[0]=345fht
ignore[1]=rthfg56
.
.
.
ignore[n]=49568g

Here is the code. Is this even possible to do? please help



Code:
 
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)
      {
            z=0
            while ( z <= leanth_of_ignore )
            {
                if ( ignore[z] == $2 )
               {
               foundTermEvent = 0;
               { print ignore[z] }
               z=31
               }
               else
               {
               print;
               { print ignore[z] }
               z++
               }
            }
      }
      if (substr($0, 1, 18) == "Termination Event:")
      {
        foundTermEvent=1;
      }
    }'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing array elements in reverse

Hello Experts, I am trying to print an array in reverse. Input : 1. Number of array elements 2. The array. Eg: 4 1 2 3 4 Expected Output (elements separated by a space) : 4 3 2 1 My Code : (6 Replies)
Discussion started by: H squared
6 Replies

2. 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

3. UNIX for Dummies Questions & Answers

printing array elements

Is there a way to print multiple array elements without iterating through the array using bash? Can you do something like... echo ${array}and get all those separate elements from the array? (2 Replies)
Discussion started by: jrymer
2 Replies

4. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. Shell Programming and Scripting

Calling array inside awk

Hello I have the file df.tmp FS is actually the / FS but escape character\ and end of line $ is used in order to fetch exctly / and not other filesystems. awk '/\/$/ {print $(NF-1)+0}' df.tmp will work properly and return a value eg. 60 but when I am trying to issue the command with the array... (3 Replies)
Discussion started by: drbiloukos
3 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 help: how to compare array elements against a variable

i have an array call ignore. it is set up ignore=34th56 ignore=re45ty ignore=rt45yu . . ignore=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... (2 Replies)
Discussion started by: usustarr
2 Replies

8. 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

9. Shell Programming and Scripting

using array inside awk

Hi All, I have the following code sequence for reading some bulk file and moving the content to two different arrays. while read data do THREEG_PATTERN=`echo $data | egrep "3G"` if then NEW_THREEG_PATTERN=`echo $THREEG_PATTERN | cut -d " " -f2` ... (12 Replies)
Discussion started by: subin_bala
12 Replies

10. 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
Login or Register to Ask a Question
STAG-DIFF(1p)						User Contributed Perl Documentation					     STAG-DIFF(1p)

NAME
stag-diff - finds the difference between two stag files SYNOPSIS
stag-diff -ignore foo-id -ignore bar-id file1.xml file2.xml DESCRIPTION
Compares two data trees and reports whether they match. If they do not match, the mismatch is reported. ARGUMENTS -help|h shows this document -ignore|i ELEMENT these nodes are ignored for the purposes of comparison. Note that attributes are treated as elements, prefixed by the containing element id. For example, if you have <foo ID="wibble"> And you wish to ignore the ID attribute, then you would use the switch -ignore foo-ID You can specify multiple elements to ignore like this -i foo -i bar -i baz You can also specify paths -i foo/bar/bar-id -parser|p FORMAT which parser to use. The default is XML. This can also be autodetected by the file suffix. Other alternatives are sxpr and itext. See Data::Stag for details. -report|r ELEMENT report mismatches as they occur on each element of type ELEMENT multiple elements can be specified -verbose|v used in conjunction with the -report switch shows the tree of the mismatching element OUTPUT If a mismatch is reported, a report is generated displaying the subpart of the tree that could not be matched. This will look like this: REASON: no_matching_node: annotation no_matching_node: feature_set no_matching_node: feature_span no_matching_node: evidence no_matching_node: evidence-id data_mismatch(:15077290 ne :15077291): evidence-id AND evidence-id Due to the nature of tree matching, it can be difficult to specify exactly how trees do not match. To investigate this, you may need to use the -r and -v options. For the above output, I would recommend using stag-diff -r feature_span -v ALGORITHM Both trees are recursively traversed... see the actual code for how this works The order of elements is not important; eg <foo> <bar> <baz>1</baz> </bar> <bar> <baz>2</baz> </bar> </foo> matches <foo> <bar> <baz>2</baz> </bar> <bar> <baz>1</baz> </bar> </foo> The recursive nature of this algorithm means that certain tree comparisons will explode wrt time and memory. I think this will only happen with very deep trees where nodes high up in the tree can only be differentiated by nodes low down in the tree. Both trees are loaded into memory to begin with, so it may thrash with very large documents AUTHOR Chris Mungall cjm at fruitfly dot org SEE ALSO
Data::Stag perl v5.10.0 2008-12-23 STAG-DIFF(1p)