The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing a variable inside another variable. reconflux Shell Programming and Scripting 2 12-05-2008 05:07 PM
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 08:28 PM
passing value to a variable in a SQL kamitsin UNIX for Advanced & Expert Users 4 08-30-2007 04:21 PM
variable passing to sed Manish Jha Shell Programming and Scripting 2 08-18-2006 12:54 PM
Variable passing whugo UNIX for Dummies Questions & Answers 2 01-25-2006 06:56 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-18-2009
chowdhut chowdhut is offline
Registered User
  
 

Join Date: May 2009
Location: CT, USA
Posts: 4
Passing KSH variable to AWK with two loops

Hi, I need some help to figure out why an outer for loop KSH variable does not decode in AWK but inner for loop does. Below is my code,
If I hard code variable 'SUBSEQ' in AWK it works but if I try to pass the SUBSEQ from KSH, it does not and when I pass the variable 'NAM' from KSH it works: I have all the file below. I need help so code gives output if I uncomment the line
#SUBSEQ = "'$sub'"; and comment out the hardcode
SUBSEQ = "0633-009_001200008|225065338468009";

Not following why the if block does not evaluate SUBSEQ if ( arr[j,1] == SUBSEQ && && arr[j,2] == NAM)

#! /bin/ksh


# read subject and sequence
set -A subseq_array $(<subseq.txt)


# read the applicable QVALS Order for the study ( can be from define)

set -A qnam_array $(<qnam.txt)


for sub in ${subseq_array[@]}
do
for n in ${qnam_array[@]}
do

#print $sub ;

`awk -F ':' 'BEGIN { }
{

{
#SUBSEQ = "'$sub'";
SUBSEQ = "0633-009_001200008|225065338468009";
NAM = "'$n'";
NULL = " |";
}



for(i=1;i<=NF;i++)
{
arr[NR,i]=$i;
}
}

END{


for(j=1;j<=NR;j++)
{

if ( arr[j,1] == SUBSEQ && arr[j,2] == NAM) {
{printf("%s|",arr[j,3]);}
exit; }
}



for(j=1;j<=NR;j++)
{


if ( arr[j,1] == SUBSEQ && arr[j,2] != NAM) {
{printf("%s",NULL);}
exit; }

}






}' supp_q.txt >> out1.txt`

done
print $sub >> out1.txt
break;
done



The files:
subseq.txt
=========

0633-009_001200008|225065338468009
0633-009_001200008|225065338468010
0633-009_001200009|225065338468008
0633-009_001200018|225065338468009
0633-009_001200018|225065338468011

qnam.txt
=======

CMBRTRM
CMCLAS1
CMCLAS2
CMCLAS3
CMCLSCD1
CMCLSCD2
CMCLSCD3
CMROUTE

source file that I am reading from
supp_q.txt
==========

0633-009_001200008|225065338468009:CMBRTRM:albuterol
0633-009_001200008|225065338468009:CMCLAS1:respiratory system
0633-009_001200008|225065338468009:CMCLAS2:drugs for obstructive airway diseases
0633-009_001200008|225065338468009:CMCLAS3:adrenergics for systemic use
0633-009_001200008|225065338468009:CMCLSCD1:R
0633-009_001200008|225065338468009:CMCLSCD2:R03
0633-009_001200008|225065338468009:CMCLSCD3:R03C
0633-009_001200008|225065338468010:CMCLSCD2:R03
0633-009_001200008|225065338468010:CMCLSCD3:R03C
0633-009_001200009|225065338468008:CMBRTRM:albuterol
0633-009_001200009|225065338468008:CMCLAS1:respiratory system
0633-009_001200009|225065338468008:CMCLAS2:drugs for obstructive airway diseases
0633-009_001200009|225065338468008:CMCLSCD3:R03C
0633-009_001200018|225065338468009:CMCLAS2:drugs for obstructive airway diseases
0633-009_001200018|225065338468011:CMROUTE:RESPIR

initial output file that I am writing to from AWK:
============
CMBRTRM|CMCLAS1|CMCLAS2|CMCLAS3|CMCLSCD1|CMCLSCD2|CMCLSCD3|CMROUTE|USUBJID|CMSEQ|

what the output needs to be:
========================

CMBRTRM|CMCLAS1|CMCLAS2|CMCLAS3|CMCLSCD1|CMCLSCD2|CMCLSCD3|CMROUTE|USUBJID|CMSEQ|
albuterol|respiratory system|drugs for obstructive airway diseases|adrenergics for systemic use|R|R03|R03C| |0633-009_001200008|225065338468009
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0