Parsing comma delimited text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing comma delimited text file
# 1  
Old 02-23-2007
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  
Old 02-23-2007
not tested though! Smilie

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  
Old 02-23-2007
Code:
IFS=","
while read dir days
do
 if [[ $days -ge 7 ]]
 then
   echo $dir # rm -r $dir
 fi
done<file

# 4  
Old 02-23-2007
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 Smilie )

And moreover what about the case when days is less than 7 ? Smilie
# 5  
Old 02-23-2007
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 Smilie )

And moreover what about the case when days is less than 7 ? Smilie
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  
Old 02-23-2007
Thanks both for the speedy replies. It certainly helped me get started! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help on an old post - How to convert a comma delimited string to records or lines of text?

Hi, Apologies in advance to the moderator if I am posting this the wrong way. I've searched and found the solution to an old post but as it is a very old post, I don't see an option to update it with additional question. The question I have is in relation to the following post: How to... (6 Replies)
Discussion started by: newbie_01
6 Replies

2. Shell Programming and Scripting

Help/Advise please for converting space delimited string variable to comma delimited with quote

Hi, I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file. Example of the SQL will be For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING. I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. UNIX for Dummies Questions & Answers

How to convert a comma delimited string to records or lines of text?

Hi, I am not sure if I've posted this question before. Anyway, I previously asked about converting lines of text into a comma delimited string. Now I am needing to do the other way around ... :( :o Can anyone advise how is this possible? Example as below: Converting records/lines to... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. UNIX for Dummies Questions & Answers

How to change a line of text to a comma delimited string?

Hi, Is there a one-liner that I can use to change a line of text into a comma delimited string? For example, convert user1 user2 user3 user4to user1,user2,user3,user4Currently using while read x, although got the extra comma at the end that I have to remove manually. Please... (5 Replies)
Discussion started by: newbie_01
5 Replies

5. Shell Programming and Scripting

Parsing and filtering multiline text into comma separated line

I have a log file that contains several reports with following format. <Start of delimiter> Report1 header Report1 header continue Report1 header continue Record1 header Record1 header continue Record1 header continue field1 field2 field3 field4 ------... (1 Reply)
Discussion started by: yoda9691
1 Replies

6. UNIX for Dummies Questions & Answers

Comma delimited file

Hi All, I have output of sql saved in comma separated file. Now i need to read line by line this file and assign word to a unix variable for further processing Eg: Test file world, 1, 3, 4 earth,2,3,4,5 moon,1,2,3,4 Output should be word1= world word2=1 echo " first word... (7 Replies)
Discussion started by: gwrm
7 Replies

7. UNIX for Advanced & Expert Users

pattern matching with comma delimited text

Hi, I have two files that I need to match patterns with and the second file has comma delimited rows of data that match but I'm having trouble getting a script to work that gives me the match output to these sets : file 1: PADG_05255 PADG_06803 PADG_07148 PADG_02849 PADG_02886... (8 Replies)
Discussion started by: greptastic
8 Replies

8. Shell Programming and Scripting

How do you delete multiple text from a comma delimited file

I would like to know code that will delete multiple text from a comma delimited file. For example, how would the comma delimited file below delete the word 'PEST' in Perl language (previously an excel file that was converted to a csv and the last column was PEST): 1, 2,43,34, bosx,PEST 1,... (1 Reply)
Discussion started by: dolo21taf
1 Replies

9. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies

10. Shell Programming and Scripting

Comma Delimited file

I have a comma delimited file that sometimes has addresses details in. The problem is that the address detail can be seen as: "Sample House, Sample Road". When I run a script specifying the file is comma delimited I would like it to ignore comma's that are in between speech marks. Is this... (2 Replies)
Discussion started by: dbrundrett
2 Replies
Login or Register to Ask a Question