Test argument error, unable to solve


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Test argument error, unable to solve
# 8  
Old 08-23-2010
Please show sample input and sample output.
May be being thick but I can't see what the array sum[i] is for.
# 9  
Old 08-23-2010
Hi scottn, yes you're right, its not an awk error. I'm using this statement in a ksh script on solaris... :-)

I'm basically trying to send in a .csv file full of numbers and N/A's and getting the sum appended to it..

Code:
awk  -F"," '{for (i=1;i<=NF ; ++i) { if($i !~ /N\/A/) {sum[i] += $i;}} if (i > max) max=i }
    END { s=""; for (i=1; i<=max; ++i) { printf "%s%s", s, sum[i]; s=",";} printf "\n" }' format.csv > ffname
    cat format.csv

format.csv is something like this

Code:
20100803,N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, , 
20100804, 183,  234,  29,  31,  0,  0,  0,  0,  25,  127,  6,  21,  285,  49,  0,  0,  0,  0,  217,  2,  27,  0,  968,  332, 
20100802,N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, , 
20100803,N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, ,

I'm adding the columns corresponding to the dates...

so my result should be :-

Code:
183,  234,  29,  31,  0,  0,  0,  0,  25,  127,  6,  21,  285,  49,  0,  0,  0,  0,  217,  2,  27,  0,  968,  332,

I'm getting the result but with this error on the console, which i don't want...

Code:
finale4[71]: N/A,: unknown test operator



---------- Post updated at 09:43 PM ---------- Previous update was at 09:40 PM ----------

@methyl : - sum[i] is the array that holds my column sum...
# 10  
Old 08-23-2010
Hi.

You probably want to change the for(i=1;... to for(i=2;... to exclude those large date numbers at the start.

Apart from that, from the code you show (none of which is ksh), this work fine in Solaris (10):

Code:
$ ./SumUp
183,234,29,31,0,0,0,0,25,127,6,21,285,49,0,0,0,0,217,2,27,0,968,332,0,0,

What is at "line 71"?

Add:

Code:
set -x

at the top of your script (after the shebang, if you have one) and post the output.

Last edited by Scott; 08-23-2010 at 01:45 PM.. Reason: Haha... those "PK-looking numbers" are dates!
# 11  
Old 08-23-2010
Thanks. Didn't realise you were summing columns not rows. I think one or two other posters made the same assumption.


This error message comes from shell not awk. The "71" is a line number very near to the error within a shell script called "finale4".
Quote:
finale4[71]: N/A,: unknown test operator


---------- Post updated at 17:34 ---------- Previous update was at 17:25 ----------

We can generate a similar error using a test script with the same name as yours.


Code:
#!/bin/ksh
if [ "abc" N/A, "abc" ]
then
        echo "ok"
fi

./finale4[2]: N/A,: unknown test operator


Last edited by methyl; 08-23-2010 at 01:35 PM.. Reason: paste error
# 12  
Old 08-24-2010
it's quite a long piece of code. I've used the awk commands in ksh. Tried with (for i=2..) but in vain...

set -x gave me the following output..

Code:
+ writer_reader
finale4[89]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
finale4[71]: N/A,: unknown test operator
+ [ 1 -lt 1 ]
+ exit

writer_reader is the name of the function where this command is used. I've put only a part of the console o/p above (the one that concerns the error).

---------- Post updated at 01:45 PM ---------- Previous update was at 10:59 AM ----------

what does the number in the [] bracket indicate exactly? It is not the line number, of that i am sure. Then what is it and how do i identify the location of the error?
# 13  
Old 08-24-2010
Quote:
Originally Posted by pravsripad
iwhat does the number in the [] bracket indicate exactly? It is not the line number, of that i am sure. Then what is it and how do i identify the location of the error?
It is (albeit sometimes incredibly vaguely) related to the error - quite often the last point at which it doesn't make any sense to continue.

I don't really want to spend my day guessing, and second-guessing where your problem might be.

So at this point I would suggest that you post your script (at least the first 100 lines of it).
# 14  
Old 08-24-2010
Hi, the script is 1000 line huge... The error is definitely coming from those three lines... Could it be that the "," is also getting input along with the "N/A" .... i mean the "N/A," will it matter.. ?
Tried but didn't work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script that check the argument passed to it and prints error if test condition is not met

I want to make a script that check for the argument passed to it and generates an error in case any character/string argument passed to it. I am using below code, but its not working. can anyone help. #!/bin/bash if ]; then echo 'An integer argument is passed to the script hence... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

2. UNIX for Dummies Questions & Answers

Test: argument expected error in shell script

Hi, I am trying to write a small script that validates if there exist files that start with a pattern in a given directory. Below is the piece of my script: #!/usr/bin/ksh BTFDIR=/opt/ships/temp if then echo 'found' else echo 'not found' fi When I run this... (2 Replies)
Discussion started by: snvniranjanrao
2 Replies

3. Shell Programming and Scripting

Error- test: argument expected

check_build_info_table() { if then export build_info_table=`sqlplus -s sna/dbmanager <<! set pagesize 0 heading off feedback off SELECT DISTINCT TABLE_NAME FROM ALL_TABLES WHERE OWNER = 'XYZ' AND TABLE_NAME = 'MY_TABLE'; exit !` ... (3 Replies)
Discussion started by: ambarginni
3 Replies

4. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

5. Shell Programming and Scripting

error : test: argument expected

Hello all, I am trying to figure out why i am getting an error while executing the script...altought it seems like its work...but still get the test arguement error...any help would be appericiate...this script basically connects to any oracle db ( just have to pass db name to it)... (4 Replies)
Discussion started by: abdul.irfan2
4 Replies

6. Shell Programming and Scripting

test: argument

Hi, I having trouble with a test numeric value. Here is my code : nb_wanted=$(cat ${type_proto} | grep "#nbr_#branche#" | grep $branche | awk '{print $3}') if ; then nb_ready=$(cat ${fic_tmp_listeSTAF} | wc -l) ... (2 Replies)
Discussion started by: Aswex
2 Replies

7. Shell Programming and Scripting

test: argument expected

# to search a file if it exists and whether its readable or not # if yes print its first 5 lines echo enter the filename to be searched read fname if #-d $fname then echo file doesn exists elif then echo its a directory elif then cat $fname else echo its not readable fi # end of... (9 Replies)
Discussion started by: gotam
9 Replies

8. UNIX for Dummies Questions & Answers

"test: argument expected" error

Hi, No need to say I'm new to unix shell scripting. I have a very simple script that goes this way: for datos in `ls -rt $UNXLOG/26-Jan*` do export arch=`echo $datos |cut -d, -f1` if then export linea1=`grep Debut ${arch}` export horatot=`echo $linea1 |cut -d' ' -f5` ... (7 Replies)
Discussion started by: mvalonso
7 Replies

9. Shell Programming and Scripting

ERROR-> test: argument expected , what does it mean?

I am trying to compare two integer variables in the if statement, but i am getting this "test:argument expected". What am i missing? Why is the if loop not executing correctly? trunkPCM="100000"; more $FILE |while read line do PCM=`echo $line | awk '{ print $2 }'` ... (4 Replies)
Discussion started by: tan102938
4 Replies

10. Shell Programming and Scripting

Facing test: argument expected ERROR

Hi All, When i run the below code : v_shortfield = "" if ; then echo "ravi" else echo "kumar" fi i am getting output as : sam.ksh: test: argument expected kumar Why i am getting error test:argument expected and why i am not getting output as "ravi" :confused: (5 Replies)
Discussion started by: rkrgarlapati
5 Replies
Login or Register to Ask a Question