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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do you delete multiple text from a comma delimited file dolo21taf Shell Programming and Scripting 1 02-20-2008 05:12 AM
Combining information from a comma delimited file vzismann UNIX for Dummies Questions & Answers 1 08-06-2007 07:20 PM
Loading a comma Delimited file into an Array grandtheftander UNIX for Dummies Questions & Answers 2 07-26-2006 02:19 PM
Converting Tab delimited file to Comma delimited file in Unix charan81 Shell Programming and Scripting 22 01-20-2006 09:24 AM
Comma Delimited file dbrundrett Shell Programming and Scripting 2 04-05-2004 11:50 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-23-2007
chengwei chengwei is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 30
Question Parsing comma delimited text file

I need to delete a set of files in certain directories if there're older than a certain number of days. So I have a text file, with each line containing the directory & number of days.

The format is like this:
dirA,5
dirB,7

How do I write script to iteratively parse this text file & delete the files in the directories base on the number of days?

Any help to get started is appreciated!
  #2 (permalink)  
Old 02-23-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960
not tested though!


Code:
awk -F"," '{ print $1, $2}' file | while read dir days
do
  find $dir -maxdepth 1 -type f -mtime +$days -name '*.*' -print | xargs rm -f
done

  #3 (permalink)  
Old 02-23-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
IFS=","
while read dir days
do
 if [[ $days -ge 7 ]]
 then
   echo $dir # rm -r $dir
 fi
done<file

  #4 (permalink)  
Old 02-23-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960
Quote:
Originally Posted by anbu23
Code:
IFS=","
while read dir days
do
 if [[ $days -ge 7 ]]
 then
   echo $dir # rm -r $dir
 fi
done<file
Quote:
# rm -r $dir
I believe this would delete all the files and inclusive of subdirectories if there are any

and OP had requested only for deletion of files ( If am not wrong )

And moreover what about the case when days is less than 7 ?
  #5 (permalink)  
Old 02-23-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by matrixmadhan
I believe this would delete all the files and inclusive of subdirectories if there are any

and OP had requested only for deletion of files ( If am not wrong )

And moreover what about the case when days is less than 7 ?
You are right.It will all the files and its sub directories.

Just for example i am checking whether days is greater than 7.
  #6 (permalink)  
Old 02-23-2007
chengwei chengwei is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 30
Thanks both for the speedy replies. It certainly helped me get started!
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0