how to loop through non-empty files with shell script on AIX


 
Thread Tools Search this Thread
Operating Systems AIX how to loop through non-empty files with shell script on AIX
# 1  
Old 02-12-2009
how to loop through non-empty files with shell script on AIX

I have av script that loops through some statistic files to create a report. We would like to only loop through non-empty files as these files create an empty report-line.
I have figured out how to find the non-empty files, but not how to loop through only those files.
Here is the code that finds the non-empty files:
find stat.* -type f -size +1;

My current loop looks somewhat like this:
for i in stat.* ; do
echo $i
done
# 2  
Old 02-12-2009
Just combine those two:
Code:
for i in `find stat.* -type f -size +1` ; do
    echo $i
done

Hint for the next time: source code and listings get easier to read if you use [ code][/code ] tags (minus the spaces)
# 3  
Old 02-12-2009
Thanks for the quick reply. I also found this solution.
Code:
Files=`find stat.* -type f -size +1`;
for i in $Files
do
  echo $i
done

which is just the same. I thought I had tried your solution, but maybe I forgot the `` .
# 4  
Old 02-14-2009
I suggest that you change stat.* to stat.\*
# 5  
Old 02-20-2009
for i in stat.* ; do
[[ -s $i ]] && echo $i # That works too
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to delete empty files from specific locations

Hi, I need help in regard to developing a shell script to delete empty files from multiple specific locations. The directory paths will be stored in a text file. So the requirement is to read the text file for one specific path and then remove empty files from that particular path. Looping through... (4 Replies)
Discussion started by: Khan28
4 Replies

2. UNIX for Beginners Questions & Answers

Shell script to loop through files

Hi Team, I am new to shell scripting. I have the below requirement 1) Say if i am searching for 20160815 in a directory /dir 2) Now i need to get the files present in dir whose time stamp in greater than or equal to 20160815 3) Then i need to find the string 20160815 from the set of... (3 Replies)
Discussion started by: Rajendra Kalepu
3 Replies

3. Shell Programming and Scripting

Shell script to remove empty files

Hi All, Can anyone please write a shell script to remove the empty files using an if condition. please help me out , urgent thanks (6 Replies)
Discussion started by: muthi_murali
6 Replies

4. UNIX for Dummies Questions & Answers

Using Shell Script To Loop Program Through Multiple Text Files

Hello, So I have approximately 300 files of raw data (.txt) files that I am using to perform statistical analysis. I have been able to construct a Fortran program that is able to perform my statistical analysis on a file by file basis. However, I now want to be able to loop program through... (19 Replies)
Discussion started by: Jimmyd24
19 Replies

5. UNIX for Dummies Questions & Answers

Writing a loop to process multiple input files by a shell script

I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files: for i in 250.*; do || awk... (4 Replies)
Discussion started by: evelibertine
4 Replies

6. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

7. Shell Programming and Scripting

Need to check for empty file in C shell script

I am running a C shell script. I have an output file from a previous step and I need to run "something" in the next step to check if the file is empty. If the file is empty, then the job script should finish EOJ. If the file is not empty then the job script should abend. Please help Thanks. (4 Replies)
Discussion started by: jclanc8
4 Replies

8. UNIX for Dummies Questions & Answers

Initializing files to empty in korn shell

hello, i want to know how to initialize a file to an empty one in korn shell scripting? i'm using a file name and building it during a while loop using >>. The problem occurs when the file is not empty before reaching the while loop. therefore, i want to initialize it before the loop to get... (6 Replies)
Discussion started by: alrinno
6 Replies

9. Shell Programming and Scripting

Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it. Requirement: files are ftp to... (1 Reply)
Discussion started by: dba_nh
1 Replies

10. UNIX for Advanced & Expert Users

how to delete empty files in a shell script

I'm trying to figure out a way to delete empty files in a directory. I have a cron that runs and creates a flat file every 15 mins. However, most times at night the flat file will be empty. I'd like to run a script to delete empty files that end with *.dat Any suggestions? Rich (1 Reply)
Discussion started by: rpnuge
1 Replies
Login or Register to Ask a Question