how to check weather file is blank or not?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to check weather file is blank or not?
# 1  
Old 12-15-2007
how to check weather file is blank or not?

Dear All

I want to do following task. Kindly suggest.

In my script every hour one file is genarated. say xyz.txt.

Now if this file contain some data then i want to do task A and if file is blank then i want to do nothing.

Kindly help me to do this.

regards
jaydeep
# 2  
Old 12-15-2007
How blank is blank? Zero bytes or just no alphanumerics?

I would use "egrep" to look for alphabetric characters.
# 3  
Old 12-15-2007
If by "blank" you mean an empty file, you could use the test utility.

Code:
[ -s xyz.txt ] && {
     do something
}

# 4  
Old 12-15-2007
there is no alphanumerical. Actually i am generating this file in my script. It will contain some word if my my some database not loaded in system. If all database loded in system is ok then there is no op in that file.

So plz reply.
# 5  
Old 12-15-2007
Quote:
Originally Posted by porter
How blank is blank? Zero bytes or just no alphanumerics?

I would use "egrep" to look for alphabetric characters.


there is no alphanumerical. Actually i am generating this file in my script. It will contain some word if my my some database not loaded in system. If all database loded in system is ok then there is no op in that file.

So plz reply.
# 6  
Old 12-15-2007
Code:
if [ ! -s myfile ]
then
  echo "myfile is empty"
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 check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : «┐┐ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

2. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

3. Shell Programming and Scripting

How to check if the file is empty or has blank space.?

Hi, I am using KSH. I am trying to check if the output file is empty or not. I tried with ] but what i see is my file is empty but still manages to have a size of 1 instead of 0. But my file doesnot have anything its empty. I am not sure how to check this. can any one help? (10 Replies)
Discussion started by: Sharma331
10 Replies

4. Shell Programming and Scripting

Use PYTHON to collect data weather and print in new file

Hi all, i have a task to do with Python and because i'm a beginner on it i would like your help on this. Create a python script that: Every hour collect the Temperature (e.g. 29C) and Current Condition (e.g. Clear) from this website wunderground.com/global/stations/54511.html Create a CSV... (0 Replies)
Discussion started by: ragaga123
0 Replies

5. 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

6. Shell Programming and Scripting

check if return value is blank

Hi, i am trying to get the no of users using nofActUsers=$(echo /usr/sbin/lsof -l | grep "/mast/data/users" ) it will return blank, if the user does nto have permissions to run the script. Now I need to check if the valueis blank i have route to another script else the user has to... (1 Reply)
Discussion started by: Satyak
1 Replies

7. Linux

Check weather a file is in use or not?

Hi, Hi want to check weather a file is being used by using a command or java code or shell script. So, can any body give me some idea.. Thanks Buddhika (3 Replies)
Discussion started by: cse.buddhika
3 Replies

8. Shell Programming and Scripting

save weather radar to local time-named file every 15 minutes

I think I can do this myself now, but I am always amazed by how people can do things cleaner and simpler than I end up doing... Using cron, I want to save the image found at: http://radar.weather.gov/ridge/Conus/RadarImg/centgrtlakes.gif every 15 minutes to a local file , such as ... (1 Reply)
Discussion started by: brucewestfall
1 Replies

9. UNIX for Dummies Questions & Answers

How to verify weather it is a ebcdic file or not

Hi all, Please tell me how to verify weather it is a ebcdic file or not . I checked with file commond but it is giving like International Language text. Regards, Chaitu (0 Replies)
Discussion started by: c_chaitanya
0 Replies

10. UNIX for Dummies Questions & Answers

check for the first character to be blank

I'm having a problem when the first line or first character of a file is blank. I need to get rid of both of them when they occur but don't want to delete the line. Does anyone have any suggestions? (7 Replies)
Discussion started by: anthreedhr
7 Replies
Login or Register to Ask a Question