Problem with awk array when loading from shell variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with awk array when loading from shell variable
# 8  
Old 06-19-2013
Double quote the $LINENUMBER_JOBID.
# 9  
Old 06-19-2013
Thanks..tried with , separator and worked fine.

I have almost made my script except the printing problem.Iam getting error in when i want to print between the start point and endpoint and more than start point.Can you please shed some light,,how can i overcome from this problem..

Code:
nawk -v JOBID=$MAX_JOB -v LINENO=$LINENUMBER_JOBID 'BEGIN {SUBSEP=",";START="N";
printem();
split(LINENO,Val,SUBSEP);
ARRLENGTH=split(LINENO,Val,SUBSEP);
print "ARRAY LENGTH***********"ARRLENGTH
}
function printem() {
    for (i in Val) { delete Val[i] }
    for (i in a) { delete a[i] }
}
{
for (i=1;i<=ARRLENGTH;i++)
{
  print "***********************LOOP*************************"i
  split(Val[i],a,"|");
  print "JOBID***********"JOBID
  print "Val["i"]::a[1]::a[2]***********"Val[i]"::"a[1]"::"a[2]
  if (JOBID==a[2])
  {
     print "&&&&&&&&&MATCH FOUND&&&&&&&&&&"
     if (START=="N")
     {
        STARTPOINTER=a[1];START="Y";
        ENDPOINTER=STARTPOINTER;
        print "STARTING POINT************"STARTPOINTER
        print "ENDING POINT************"ENDPOINTER
     }
     if (a[1] > STARTPOINTER)
     {
       print "Only EndPointer needs to be changed**************"
       ((ENDPOINTER=a[1]-1))
       print "$$$$$$$$$$$$$$END POINT REACHED$$$$$$$$$$$$$$$"ENDPOINTER
     }
  }
  else
  {
     print "//////////////MATCH NOT FOUND////////////////"
     if (START=="Y" && a[1] > STARTPOINTER )
     {
       print "^^^^^^^^^^^^^STARTING POINT REACHED^^^^^^^^^^^"STARTPOINTER
       ((ENDPOINTER=a[1]-1))
       print "$$$$$$$$$$$$$$END POINT REACHED$$$$$$$$$$$$$$$"ENDPOINTER
       START="N";
NR==STARTPOINTER,NR==ENDPOINTER { print NR"|"$0}
      if (a[1] < STARTPOINTER)
     {
       print "Come out of the for loop**************"
       print "$$$$$$$$$$$$$$Block should be printed from starting point to EOF$$$$$$$$$$$$$$$"STARTPOINTER
NR>=STARTPOINTER { print NR"|"$0 }
       printem();exit;
     }
  }
}
}' $FILE

---------- Post updated at 06:53 AM ---------- Previous update was at 06:43 AM ----------

Please find the below expected output which i want to use it in the above script..

Code:
Expected O/p:
eaits001z$ nawk 'NR==102093,NR==102097 { print NR"|"$0} ' $FILE
102093|2013 Jan 23 09:12:02:716 IST +0 BW.TEST-2-Process_Archive Debug [BW-User] DEBUG Job-107544 [UtilityServices/BWFLIB_Logging/BWFLIB_getLogger.process/GA_WL_LOGDEBUG]: Wed, Jan 23, 2013, 09:12:02 698[1111732318]::
102094| LogMessage::CallSYs1AndSystem2SubProcess:: CallSystem1AndSystem2
102095| TrackingInfo:: System2ServicevCustomerRequest-382_1358932322623
102096| CustomId:: 192.168.248.250:6961937c:13a2b960ad6:-7ffd
102097|

# 10  
Old 06-24-2013
Help required!!

Dear All,

Iam unable to use the print statement in the final stage of my awk..Any help would be much appreciated.

Thanks and Regards,
cskumar
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

2. Shell Programming and Scripting

Pass awk array variable to shell

Hi, all suppose I have following myfile (delimited by tab) aa bb cc dd ee ffand I have following awk command: awk 'BEGIN{FS="\t"}{AwkArrayVar_1=$1;AwkArrayVar_2=$2};END{for(i=0; i<NR; i++) print i, AwkArrayVar_1, AwkArrayVar_2,}' myfileMy question is: how can I assign the awk array... (7 Replies)
Discussion started by: littlewenwen
7 Replies

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

4. Shell Programming and Scripting

Problem using shell variable in awk if condition

Hi friends, I'm having a bit of a problem using shell variable in an awk if statement. Please note that i'm using -v option as listed in many forums but I still don't get it working. Here's my code. Kindly help as I've gone crazy trying to work this out :wall: #!/bin/bash -xv ... (4 Replies)
Discussion started by: vishwas.s
4 Replies

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

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

7. Shell Programming and Scripting

saving awk value in a bash array variable

hi all i am trying to save an awk value into an array in bash: total=`awk '{sum+=$3} END {print sum}' "$count".txt"` ((count++)) the above statement is in a while loop.. $count is to keep track of file numbers (1.txt,2.txt,3.txt,etc.) i get the following error: ./lines1:... (1 Reply)
Discussion started by: npatwardhan
1 Replies

8. Shell Programming and Scripting

Parameter Problem With an Array Variable

Hi, I have two bash shell scripts: test: rrdhcp78-120:test_data msb65$ cat ~/bin/test #!/bin/sh array1=() echo 'elements in array1:' ${#array1} ~/bin/test2 $array1 test2: rrdhcp78-120:test_data msb65$ cat ~/bin/test2 #!/bin/sh array2=${1} (5 Replies)
Discussion started by: msb65
5 Replies

9. Shell Programming and Scripting

Function loading in a shell scripting like class loading in java

Like class loader in java, can we make a function loader in shell script, for this can someone throw some light on how internally bash runs a shell script , what happenes in runtime ... thanks in advance.. (1 Reply)
Discussion started by: mpsc_sela
1 Replies

10. Shell Programming and Scripting

AWK program with array variable

Hi, I made a small awk program just to test array variables. I couldn't find anything wrong with it. But it doesn't give out valid numbers.( just 0.00 ) Do you see any problem that I didn't see? Thanks in advance! Here is the program: ################################## BEGIN { FS =... (4 Replies)
Discussion started by: whatisthis
4 Replies
Login or Register to Ask a Question