Shell script to delete empty files from specific locations


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to delete empty files from specific locations
# 1  
Old 01-30-2017
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 till end of the text file where path locations are defined.

Any template to meet this requirement will be greatly appreciated.

Contents of the file where multiple specified paths will be mentioned:

Code:
/b02/apps/appsoutput/UAT/INTERFACES
/b02/apps/appsoutput/UAT/FTP_XXSRDLS/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRLP/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRDP/stderr
/b02/apps/appsoutput/UAT/FTP_XXMRUP/stderr
/b02/apps/appsoutput/UAT/FTP_XXMRLP/stderr
/b02/apps/appsoutput/UAT/FTP_XXSRDL/stderr
/b02/apps/appsoutput/UAT/FTP_XXSRUPV/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRDPQ/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRDPQ/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRLPQ/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRLPQ/stderr
/b02/apps/appsoutput/UAT/XXMRDPNT/reports
/b02/apps/appsoutput/UAT/SORT_XXMRDPS/stderr


Last edited by Scrutinizer; 01-30-2017 at 11:38 PM.. Reason: Image removed
# 2  
Old 01-30-2017
Hello Khan28,

Could you please try following and let me know if this helps you(haven't tested it though).
Code:
while read path
do
    find $path -type f -size 0 -print
done < "Input_file"

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 01-31-2017
Hi R.Singh,

Thanks for your reply. I am facing some problems:

I have tried to make the shell script as:

Directory path containing file:
Code:
 vim pathfile.txt
/d02/apps/output/UAT/CMFUP/reports


Code:
while IFS='' read -r  path;
do
name="$path"
echo "Finding Empty Files from location - $name"
find  $name -empty -print
done < "$1"

ran by executing

Code:
 ./CM_Del_Emp_files.sh pathfile.txt


Results in ERROR:
Code:
sysadm@xxxh016:[UAT:NRDP]:/d01/apps/ccb/UAT/scripts/cm> ./CM_Del_Emp_files.sh pathfile.txt
Finding Empty Files from location - /d02/apps/ccboutput/UAT/CMFUP/reports
find: `/d02/apps/output/UAT/CMFUP/reports\r': No such file or directory

# 4  
Old 01-31-2017
It looks like the editor you used to create pathfile.txt was set up to use DOS (<carriage-return><newline> character pair) line terminators instead of UNIX (<newline> single character) line terminators. The extra <carriage-return> character at the end of the line is being interpreted as part of the pathname of the file; not as part of the line terminator.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 02-01-2017
Thanks All. It worked. Created a new file in Linux directly and copying directory path in that.

Code:
touch pathfile.txt
vim pathfile.txt
/p02/apps/output/UAT/CMXSU/reports/

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Find and delete empty files and directories

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to make a script, to remove all empty files and folders from current category. It also should show the name... (2 Replies)
Discussion started by: Itixop
2 Replies

2. 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

3. Shell Programming and Scripting

Script to delete empty files

I'm trying to write a shell script to files of zero length in a specified directory, but I keep getting errors. Would anybody be kind enough to look it over for issues? Thanks a bunch in advance. #!/bin/sh if then if then find $1 -type f -size 0 -print|xargs rm exit 0... (1 Reply)
Discussion started by: ScriptingIssues
1 Replies

4. 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

5. Shell Programming and Scripting

delete empty spaces at specific column

Hi All, If anybody could help me with my scenario here. I have a statement file. Example of some content: DATE DESC Debit Credit Total Rate 02-Jan-08 Lodgement 200.00 1200.00 2.51 14-Sep-07 Withdrawal 50.00 1000.00 ... (8 Replies)
Discussion started by: yonez
8 Replies

6. Shell Programming and Scripting

Need script to rename the files in different locations

Hi everybody, I need a script for below issue: I have totally 15 different locations like */COUNTRY/in. Only COUNTRy is the variable which changes for 15 countries. For each location(one per country), there will be four files like abc_def_ddmmyyyy.txt, where ddmmyyyy is the old date. ... (1 Reply)
Discussion started by: rjanardhan83
1 Replies

7. AIX

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... (4 Replies)
Discussion started by: Tessa
4 Replies

8. Shell Programming and Scripting

How to delete a particular string from different locations ?

I want to delete a particular string ( ex : berkely@abc.com ) from different locations and in different files in each location. Please help me ! (4 Replies)
Discussion started by: nani_ynm
4 Replies

9. Shell Programming and Scripting

copy similar files only both at different locations using script.

Hello, Here is the situation.............. # pwd /opt/123 # cat index.txt abc-monitor/homedir/public_html/index.php abc-monitor/homedir/public_html/test/index.php abc-monitor/homedir/public_html/test1/index.php # cp index.txt index.home # cat /root/x (1 Reply)
Discussion started by: fed.linuxgossip
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