If statement falling over on a null record. Help please.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If statement falling over on a null record. Help please.
# 1  
Old 04-29-2006
If statement falling over on a null record. Help please.

Okay i've got some code which reads a text file and loops through it and there a few if statements inside where one is failing (the one bolded).

Basically the acc column contains a list of three digit access codes, some though have null records (i.e nothing in the field) so what I want to do is if its not null to carry on to the other loops if it is null to move on to the next record.

I thought -n meant if the value is greater than 0 in length. I.e not null.

When it gets the the first null record i get the following error message

create_matrix_busy.exe: test: argument expected


This is my code so far...


while read line
do
sdate=`echo "$line" | cut -d, -f1`
edate=`echo "$line" | cut -d, -f2`
edate=`echo "$line" | cut -d, -f2`
site=`echo "$line" | cut -d, -f3`
NA=`echo "$line" | cut -d, -f4`
acc=`echo "$line" | cut -d, -f6`
calls=`echo "$line" | cut -d, -f8`
if [ -n ${acc} ]
then

if [ ${calls} -gt 0 ]
then
if [ ${NA} = 'ALL' ]
then
echo ${site},${acc}
elif [ ${NA} = 'NA*' ]
then
echo ${site},NA${acc}
fi
fi
fi

Thanks, the code will do more inside the if statements once i get those working.
# 2  
Old 04-29-2006
Code:
if [ -n "${acc}" ]

# 3  
Old 04-29-2006
Thank you.
# 4  
Old 04-29-2006
If you are using a Posix shell you should switch to the double square brackets test operator
e.g.

if [[ -n $acc ]]; then
echo \$acc defined
fi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To find record having null value

Hi All My requirement is to find the null values in particular column of a file and reject it in case if it contains null values. But the challenge is that I want a common command which can be used across different file, as the position of the column we need to check for different file may get... (14 Replies)
Discussion started by: ginrkf
14 Replies

2. Shell Programming and Scripting

Identify empty file with null record

Hi Team, I have a file abc.dat which is a empty file. But it has null record in first line. I need to identify this unique file and handle it separately. scenario 1: abc/dw> wc abc.dat 1 0 1 abc.dat abc/dw> cat abc.dat abc/dw> scenario 2: abc/dw> wc pqr.dat 0 0 0 pqr.dat... (3 Replies)
Discussion started by: kmanivan82
3 Replies

3. Programming

Derivation of values falling on date ranges

Hi Guys, I am having below tables used in oracle bal ID BALANCE BAL_DATE 1 -11.71 01-JAN-05 00.00.00 1 -405.71 02-JAN-05 00.00.00 1 -760.71 03-JAN-05 00.00.00 ref_table PRODUCT EFF_FROM_DATE EFF_TO_DATE TYPE MIN_AMT MAX_AMT CHARGE 12 01-JAN-05 00.00.00 01-JAN-06... (6 Replies)
Discussion started by: rohit_shinez
6 Replies

4. Shell Programming and Scripting

Delete lines falling in a range

Hi All, I have a file which contains lakhs of records 0136812368126 03000 Statement 1237129372189 02321 JIT 0136812368126 05000 terminal 1237129372189 05001 Utilise Is there an option to delete all lines which fall within the range 05000 to 05999? I tried... (6 Replies)
Discussion started by: swasid
6 Replies

5. Shell Programming and Scripting

extracting columns falling within specific ranges for multiple files

Hi, I need to create weekly files from daily records stored in individual monthly filenames from 1999-2010. my sample file structure is like the ones below: daily record stored per month: 199901.xyz, 199902.xyz, 199903.xyz, 199904.xyz ...199912.xyz records inside 199901.xyz (original data... (4 Replies)
Discussion started by: ida1215
4 Replies

6. Shell Programming and Scripting

If statement for null

Hi, I want to be able to check if a variable is not equal to null. I am using KSH, and am getting this error message when i run this script: : assignment requires lvalue The line which is causing the problem is as follows: if (($SFTP_DESTINATION != '' ));then if ssh... (6 Replies)
Discussion started by: Jack_Maloney
6 Replies

7. Shell Programming and Scripting

Count occurences of a numeric string falling in a range

Dear all, I have numerous dat files (1.dat, 2.dat...) containing 500 numeric values each. I would like to count them, based on their range and obtain a histogram or a counter. INPUT: 1.dat 1.3 2.16 0.34 ...... 2.dat 1.54 0.94 3.13 ..... ... (3 Replies)
Discussion started by: chen.xiao.po
3 Replies

8. Shell Programming and Scripting

Insert string 'NULL' where there is a null value

I have an input file having 7 fields delimited by , eg : 1,ABC,hg,1,2,34,3 2,hj,YU,2,3,4, 3,JU,kl,4,5,7, 4,JK,KJ,3,56,4,5 The seventh field here in some lines is empty, whereas the other lines there is a value. How do I insert string NULL at this location (7th loc) for these lines where... (8 Replies)
Discussion started by: zilch
8 Replies

9. UNIX for Dummies Questions & Answers

echo statement when find returns null

Hi, How do you echo something once when a find statement returns null results? This is when using mutiple locations and mutiple arguments. The below find command the inner loop of a nested for loop where the outter loop holds the $args and the inner loop holds the locations. find... (2 Replies)
Discussion started by: tchoruma
2 Replies

10. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies
Login or Register to Ask a Question