The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK help please - beginner COLLEGE UNIX for Dummies Questions & Answers 4 06-13-2007 04:40 AM
Beginner C frustrated1 High Level Programming 2 05-21-2007 11:14 AM
FTP - To handle error while transferring files mahalakshmi Shell Programming and Scripting 1 04-04-2007 12:56 AM
Can solaris's Zip/Unzip handle Winzip Version 10.0 Files? BCarlson UNIX for Dummies Questions & Answers 2 08-24-2006 10:44 PM
Please help. I am a beginner. Lykathea Aflame Shell Programming and Scripting 1 04-25-2006 10:46 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-10-2008
Registered User
 

Join Date: Jan 2008
Posts: 69
Question [Beginner] Handle Files

Hi,

How can I check if a text files is empty?
(With Bash Shell)
Reply With Quote
Forum Sponsor
  #2  
Old 01-10-2008
mirusnet's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 139
Quote:
Originally Posted by DNAx86 View Post
Hi,
How can I check if a text files is empty?
(With Bash Shell)
[ -s file ] && echo "File is not empty" || echo "File is empty"
Reply With Quote
  #3  
Old 01-10-2008
Registered User
 

Join Date: Jan 2008
Posts: 69
Arrow

Quote:
Originally Posted by mirusnet View Post
[ -s file ] && echo "File is not empty" || echo "File is empty"
Thank you, it works,

but can I do it in another way?
Reply With Quote
  #4  
Old 01-10-2008
mirusnet's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 139
Quote:
Originally Posted by DNAx86 View Post
Thank you, it works,

but can I do it in another way?
[ `cat file | wc -l` -gt 0 ] && echo "Not empty" || echo "empty"
Reply With Quote
  #5  
Old 01-10-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Quote:
Originally Posted by DNAx86 View Post
Thank you, it works,

but can I do it in another way?
Code:
if [ -s file ]
then
  echo "File is not empty"
else
  echo "File is empty"
fi
or

Code:
if [[ -s file ]]
then
  echo "File is not empty"
else
  echo "File is empty"
fi
Reply With Quote
  #6  
Old 01-10-2008
Registered User
 

Join Date: Jan 2008
Posts: 69
thank you everybody
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0