Welcome to the most active Linux Forum on the web.
Go Back > Forums > Other *NIX Forums > AIX
User Name
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.


Search this Thread
Old 01-25-2012, 06:20 AM   #1
Registered: Sep 2011
Posts: 50

Rep: Reputation: Disabled
Unhappy Problem with if statement in awk in AIX


My requirement is to check wheather some csv files have mandatory columns value as empty if empty log a error message or set a flag.

The problem here is that the column number varies for different CSVs hence we can not hardcode $1 or $3 like this in the awk command hence we are reading a proprty file to get the mandatory fields & then setting it to a variable by prefixing $ to that column number & checking the empty value for that column.

I am writing the following awk command :

for file in $run_count"_"*.csv; do
 echo "file name "$file
 Property_Value=$(cat ${PROPERTY_FILE_NAME} | grep "${PROP_KEY}" | cut -d'=' -f2)
 echo $Property_Value  
 for x in $array
  echo "COL numbr-"$COL_NUMBER
  flag=$(awk -F"|" '{ if( '$COL_NUMBER' ~ /^ *$/ ){ printf("1"); }}' $file )

echo "flag = "$flag
 var=$(echo $flag | cut -c1)
 echo "var= " $var
 if [ "$var" == "1" ]; then
  echo "\n error encounterd in file" $file
  echo "Successful"
It works well in ksh shell of Unix but in AIX it fails with error :
Syntax Error The source line is 1.
 The error context is
 <<<            { if( >>>  $1
 awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
 Syntax Error The source line is 1.
Then we found out that '{ if( ' is creating problem as AIX is treating this as command for awk if I can get a solution to retreive the $COL_NUMBER as $1 then my problem will be solved. as $COL_NUMBER contains $1 or $2 something like this.

Any help will be appreciated

Thanks & Regards,

Last edited by sukhdip; 01-25-2012 at 07:45 AM.
Old 01-25-2012, 09:41 AM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
The error message is from awk. Probably the version of awk on AIX is not the same as whatever other UNIX you are using for testing. Originally there was awk, then there was nawk (new awk) then there was gawk (GNU awk) ... for a full list see here. For convenience (ha!) nawk, gawk etc. are usually invoked by the awk command. The man page on each system should say which version is being used.
Old 01-27-2012, 02:46 PM   #3
LQ Newbie
Registered: Apr 2011
Posts: 23

Rep: Reputation: 3
I'm not exactly sure what your problem is, but I don't get the error that you mentioned.

I "stripped" out the "awk" statement and a couple of other statements from your script and put them
into a "test" script. I also wrote a temporary file (assuming fields separated by a | based upon your awk statement).
I received no error, when I ran my "test" script.

My temp_file (Note it begins with a blank character):
My test script:

echo "COL numbr-"$COL_NUMBER
flag=$(awk -F"|" '{ if( '$COL_NUMBER' ~ /^ *$/ ){ printf("1"); }}' $file )

echo "flag-->$flag<--"
Here is the output I get:
COL numbr-$1
You will note the "awk" statement is unchanged from your script.
Old 01-31-2012, 03:28 AM   #4
Registered: Sep 2011
Posts: 50

Original Poster
Rep: Reputation: Disabled
Hi! trbennett48
luckily solved the problem.

Thanks for the support.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash script is reprinting part of a field from an awk statement ?? SharpyWarpy Linux - General 13 04-22-2010 04:58 AM
Need help stripping statement from text file, ksh: sed awk? austin881 Programming 7 07-13-2009 05:31 PM
[SOLVED] variable substitution in awk statement emmalg Linux - Software 12 07-02-2009 09:39 AM
how to keep Field Separator in AWK when using a sub statement tmcguinness Programming 4 02-09-2009 03:24 PM
Case Statement With Aix Ksh Scripting ']['HeBroken AIX 2 02-09-2005 01:44 PM

All times are GMT -5. The time now is 05:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration