[Beginner] Handle Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Beginner] Handle Files
# 1  
Old 01-10-2008
Question [Beginner] Handle Files

Hi,

How can I check if a text files is empty?
(With Bash Shell)
# 2  
Old 01-10-2008
Quote:
Originally Posted by DNAx86
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"
# 3  
Old 01-10-2008
CPU & Memory

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

but can I do it in another way?
# 4  
Old 01-10-2008
Quote:
Originally Posted by DNAx86
Thank you, it works,

but can I do it in another way?
[ `cat file | wc -l` -gt 0 ] && echo "Not empty" || echo "empty"
# 5  
Old 01-10-2008
Quote:
Originally Posted by DNAx86
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

# 6  
Old 01-10-2008
thank you everybody
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Help me please i am beginner

i have windows 8 host on Dell Laptop vmware 9 redhat 7.2 iso downloaded through redhat official site after installation on vm it only boots into text dont show graphics Please guide:( (1 Reply)
Discussion started by: hananabbas
1 Replies

2. Shell Programming and Scripting

Help needed on Perl Script to Handle Log files that are rotated using logrotate

Hello all, I am working on a perl script which will read weblogic logfile and send the error messages to Zenoss Monitoring tool. At present the script works and it can able to send the error messages to Zenoss. The problem comes when the logrotate has been applied to the weblogic log file. At... (3 Replies)
Discussion started by: kar_333
3 Replies

3. UNIX for Dummies Questions & Answers

Difference between handle to the thread HANDLE and thread identifier pthread_t

This question might be silly but its confusing me a bit: What is the difference between handle to the thread HANDLE and thread identifier pthread_t? ---------- Post updated at 01:52 PM ---------- Previous update was at 01:48 PM ---------- Sorry I saw details and HANDLE is in windows and... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

4. UNIX for Dummies Questions & Answers

Beginner - What Should I Do First?

Hi people.... I have just started to learn unix.I want to know which version of Unix to install plus how to install it.I need to practise and make myself aware of how unix works.My thread is from an educational point of view.Also please feel free to give your suggestions as I am... (3 Replies)
Discussion started by: amit.kanade1983
3 Replies

5. Shell Programming and Scripting

How to handle one value below the other

Hi, I, have an output with 3 different values each below the other like: # echo $bla 123 345 234 Each value is in one line and for the further processing I need every single value. For example is there a way to grep line 2, like: # echo $bla | grep --line 2 345 :) Thank you in... (6 Replies)
Discussion started by: 2retti
6 Replies

6. UNIX for Advanced & Expert Users

How to handle files in use during Tar?

How you do usually deal with files in use during a backup? Is there a option to let TAR skip opened files? Or notify me an opened file is tar'ed? What's the best practice? Thanks (3 Replies)
Discussion started by: overmindxp
3 Replies

7. UNIX for Dummies Questions & Answers

Grep alternative to handle large numbers of files

I am looking for a file with 'MCR0000000716214' in it. I tried the following command: grep MCR0000000716214 * The problem is that the folder I am searching in has over 87000 files and I am getting the following: bash: /bin/grep: Arg list too long Is there any command I can use that can... (6 Replies)
Discussion started by: runnerpaul
6 Replies

8. UNIX for Dummies Questions & Answers

Awk cannot handle more than 30 files

I trying to search for lines with multiple search criterias in an archive of zipped files. But awk seems to have a limit. Any idea how to fix it? I'm on a sun solaris system. Here is my search string: gzcat -r *200808* | awk -v 'substr($0,50,11)=="11095512309" ||... (3 Replies)
Discussion started by: HugoH
3 Replies

9. Shell Programming and Scripting

FTP - To handle error while transferring files

Hi, I had written an FTP script where in I loop through the directories and transfer the files from each and every directory of Windows to UNIX. Now the problem is when 1. The connection is unable to be established I should return some error codes 2. When there is some system... (1 Reply)
Discussion started by: mahalakshmi
1 Replies

10. UNIX for Dummies Questions & Answers

Can solaris's Zip/Unzip handle Winzip Version 10.0 Files?

I understand that this version of Winzip allows 129-bit AES encryption and passwords. Can Solaris handle that yet? (2 Replies)
Discussion started by: BCarlson
2 Replies
Login or Register to Ask a Question