test file empty


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting test file empty
# 8  
Old 10-13-2009
Hi, i test but i have same problem

> cat /tmp/list

> cat test_w.sh
VALUE=5000
file=/tmp/list

#validate if file exists and is not empty file
if [ -s ${file} ]
then
for i in `cat ${file}| awk ' FS="|" { print $2 } '`
do
if [ "${i}" -eq "${VALUE}" ]
then
echo titi
else
echo toto
fi
done
else
#this means: the file not existe or is empty
echo toto
fi
> ksh test_w.sh
# 9  
Old 10-13-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 10  
Old 10-13-2009
Hi, i realized test and i have same problem

> cat /tmp/list

> cat test_w.sh
VALUE=5000
file=/tmp/list

#validate if file exists and is not empty file
if [ -s ${file} ]
then
for i in `cat ${file}| awk ' FS="|" { print $2 } '`
do
if [ "${i}" -eq "${VALUE}" ]
then
echo titi
else
echo toto
fi
done
else
#this means: the file not existe or is empty
echo toto
fi
> ksh test_w.sh
>
# 11  
Old 10-13-2009
are you sure the size of file is 0,can you paste the exit of:
Code:
ls -l /tmp/list

# 12  
Old 10-13-2009
yes, it's not empty

ls -al /tmp/list
-rw-r--r-- 1 root system 1 Oct 13 14:32 /tmp/list

cat /tmp/list

there are a blank ( white ) line

is it possible to add a condition on the "if" ? ( as [ "a$i" -ne "a" ] ??
# 13  
Old 10-13-2009
Code:
VALUE=5000
file=/tmp/list

#validate if file exists and is not empty file
if [ -s ${file} ]
then
    echo "IF"
    awk ' FS="|" { print $2 }' $file  | while read i
    do
        if [ ! "${i}" ]
        then
                echo toto
        else
                if [ "${i}" -eq "${VALUE}" ]
                then
                        echo titi
                else
                        echo toto
                fi
        fi
    done
else
        #this means: the file not existe or is empty
        echo toto
fi

# 14  
Old 10-13-2009
MySQL

thanks you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

3. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

4. Shell Programming and Scripting

while file is empty

how can i use while loop ? while file is empty do.... if not empty do ..... in bash (1 Reply)
Discussion started by: Trump
1 Replies

5. UNIX for Dummies Questions & Answers

Getting same exit status for empty and non empty file

Hi All, I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both. The value of $? is coming 0 in if part also and else part too. #!/bin/ksh if ]; then echo "data" # exit 0 echo "$?" else... (4 Replies)
Discussion started by: mavesum
4 Replies

6. Shell Programming and Scripting

how to see if the file is empty or not?

hi how can I determine, if a file is empty or not?I am using read line clause. The script should be like: while read line do if(file is empty) then; ...... done < $blacklist (1 Reply)
Discussion started by: tjay83
1 Replies

7. UNIX for Dummies Questions & Answers

Trying to empty file using > but the file size increasing when next append

AIX 5.3 / KSH I have a Java application which creates a log file a.log. I have a KSH script which does the following action cp a.log /directory2/b.log > a.log After this the file size goes to 0 as per "ls -l" Then next time when the application writes into this file, the file size... (4 Replies)
Discussion started by: firdousamir
4 Replies

8. UNIX for Dummies Questions & Answers

What's wrong with this line: if ${TEST:?} ; then echo empty; fi

I want to print "empty" if $TEST is empty. TEST= if ${TEST:?} ; then echo empty; fi But it doesn't work. What's wrong? (2 Replies)
Discussion started by: meili100
2 Replies

9. Shell Programming and Scripting

File is not empty?

How do I check to make sure a file is not zero bytes? Something like: if then ????? (7 Replies)
Discussion started by: lesstjm
7 Replies

10. Shell Programming and Scripting

if test for empty and non-existing file

How to write this condition in ksh? if myfile is empty or myfile does not exist then do action1 fi is this OK? if ] -o ] then then do action1 fi Thanks. (3 Replies)
Discussion started by: GNMIKE
3 Replies
Login or Register to Ask a Question