The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
check if file is empty stolz Shell Programming and Scripting 8 03-22-2009 11:15 PM
How to check for empty file in Perl? deepakwins UNIX for Dummies Questions & Answers 1 03-04-2008 03:00 PM
Check for empty string rahman_riyaz Shell Programming and Scripting 12 01-24-2008 03:13 AM
How can I make the for command check to see if a file is empty before executing? chrchcol Shell Programming and Scripting 3 07-29-2006 04:14 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-09-2008
shreekrishnagd shreekrishnagd is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 22
How to check if a file is empty?

Hi Masters.....
I have problem !!!
I need to check number of records in a file and if it is zero or file is empty i need to do some task.
if [Zero record]; then
echo "File s empty"
else
echo "Not empty"
fi
so how to check this condition.
I used wc -l < filename.txt => 1 for zero records
same result with- awk '{n++}' END '{print n}' filename.txt

if [ ! -s file ] => this condition is also not working out.
Can any one help me out in this please....
  #2 (permalink)  
Old 09-09-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 611
Try :


Code:
[[ -s "file" ]] && echo "Filesize not zero" || echo "Filesize zero"

Am not quite sure you are looking for the condition filesize is zero or records zero.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0