Unix file empty.. but size is greater than zero??/


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix file empty.. but size is greater than zero??/
# 1  
Old 10-08-2009
Unix file empty.. but size is greater than zero??/

Hi,


I have a file by redirecting some contents in unix shell.
Even when there is no content that is being redirected, the file size still shows greater than zero.

but even if there is no matching pattern the file APPRES has size greater than 0bytes.
Code:
awk -f AA.awk $logfile>APPRES
size=`ls -l APPRES | awk '{print $5 }'`
echo $size

output:
4

if test -s APPRES always returns true if there is no matching pattern or not.

how do i check if a file has no contents in this case

Last edited by Yogesh Sawant; 10-08-2009 at 06:00 AM.. Reason: added code tags
# 2  
Old 10-08-2009
There is a content in your APPRES file, likely some newlines or similar blanks.

Code:
wc -w APPRES

should return 0 if there is nothing useful in it.
# 3  
Old 10-08-2009
Maybe your file contains empty lines, so the file size is not zero because of the LF char ending each line.
You can compute the real file size with this command :
Code:
size=`awk -F '' 'NR { cnt+=NF } END { print cnt}' APRES`

Jean-Pierre.
# 4  
Old 10-08-2009
thanks very much. Both the solutions work good!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command size greater than or equalto

How do I find the files greater than or equal to a given size using find command. find ./ -size +0k --> Lists files greater than 0K find ./ -size 0k --> Lists the file size equal to 0K. I have other conditions to check, hence using find command. Thanks in advance. (4 Replies)
Discussion started by: deepakwins
4 Replies

2. Emergency UNIX and Linux Support

Script to fill the file system mount with empty files to desired size

We are regularly using for our testing, where we are manually filling up the mount with desired size with following command dd if=/dev/zero of=file_2GB bs=2048000 count=2000 We are planning to automate the task where taking input for % of size as one input and the name of the file system... (8 Replies)
Discussion started by: chandu123
8 Replies

3. UNIX for Dummies Questions & Answers

look for file size greater than "0" of specific pattern and move those to another directory

Hi , i have some files of specific pattern ...i need to look for files which are having size greater than zero and move those files to another directory.. Ex... abc_0702, abc_0709, abc_782 abc_1234 ...etc need to find out which is having the size >0 and move those to target directory..... (7 Replies)
Discussion started by: dssyadav
7 Replies

4. Shell Programming and Scripting

Symbolic link to an empty file shows size 2

Hi, I have created an empty file and a symbolic link to a file. But when I issue the following commands, I am getting the output 2. stat -c "%s" linkfile du -hb linkfile Why this is happening? (4 Replies)
Discussion started by: royalibrahim
4 Replies

5. Shell Programming and Scripting

shell script to check file size greater than 50M

Hi All, OS:AIX 64 bits using korn shell. Requirement: shell script to check file size greater than 50M and send mail alert. Thanks for your time! Regards, (3 Replies)
Discussion started by: a1_win
3 Replies

6. Shell Programming and Scripting

Filter the file list greater then the size specified by user

HI, Can any tell me how to filter the list of files greater than the size specified by user. The size should be provided by user as an input. Regards shiva (6 Replies)
Discussion started by: shivu
6 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

Empty directories having different size

$ls -lrt mydir total 12 drwxrwxrwx 2 nobody nobody 512 Aug 8 11:51 tmp drwxrwxrwx 2 nobody nobody 4608 Jan 19 12:20 web.cache $ ls -lrt mydir/web.cache/ total 0 $ ls -lrt mydir/tmp/ total 0 Can anyone explain me the above results? I know the o/p of ls, but this... (3 Replies)
Discussion started by: rahulrathod
3 Replies

9. Shell Programming and Scripting

Can I find wether a particular file exist and size greater than zero...help please

Can I find wether a particular file exist and size greater than zero in one line command. similar to this if && something in one if test .... e.g. if 1.) is it possible ? ... if yes how 2.) what would be the return type in case there is success or failure. I mean if both are... (4 Replies)
Discussion started by: guhas
4 Replies

10. Shell Programming and Scripting

File size greater than 0

ok I want to know how to touch a file and find out that it is greater than 0 then if it is not I want to fail the job other wise I want to success amnd go on. Can anyone help. Thanks Shannon Kammer (1 Reply)
Discussion started by: skammer1234
1 Replies
Login or Register to Ask a Question