Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Deleting files based on Substring match Post 302625901 by methyl on Wednesday 18th of April 2012 12:39:24 PM
Old 04-18-2012
Quote:
This is listing all the files not having today's date timestamp. Now I have to delete the files which are listed .Kindly help me out how I can delete the files.
Code:
#!/bin/ksh

DATE=`date +"%d%h%Y"`
DIR="/data/rfs/"
FOLDER="Test"
TARGET="${DIR}${FOLDER}"

UDATE="$(echo $DATE | tr '[a-z]' '[A-Z]')"

ls "${TARGET}" 2>/dev/null | grep -v "${UDATE}" | while read FILENAME
do
         # Remove echo when tested
         echo rm "${FILENAME}"
done
exit 0


Last edited by methyl; 04-18-2012 at 01:45 PM.. Reason: make variable same case as rest of script. change name of $FILE to $TARGET (it isn't a file). allow for no files
This User Gave Thanks to methyl For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Traversing thru dirs and deleting files based on date

Hi Folks I am pretty new to unix and shellscripting. I need help on writing logic on traversing recursively through a set of directories under a top-level folder and delete files(mostly text) which are 1 month old. Can you people help me on this? Thanks a lot Ravi (5 Replies)
Discussion started by: ravi2082
5 Replies

2. Shell Programming and Scripting

command for deleting log files based on some condition

Hello, Can anyone pls. provide me with the command for deleting files older then 15 days with a restriction to keep at least 5 files in a directory even if they are older then 15 days. Any help will be highly appreciated. Thanks, Pulkit (4 Replies)
Discussion started by: pulkit
4 Replies

3. UNIX for Dummies Questions & Answers

deleting files based on file name and modified time

Hi, I have some log files created in the following fashion Ex: file name modified date 1) s.log1 01-jan-08 2) s.log2 02-jan-08 3) s.log3 03-jan-08 4) s.log4 04-jan-08 Now I want to have the latest 2 logs and delete the others. Can you tell me the one liner /... (1 Reply)
Discussion started by: ammu
1 Replies

4. UNIX for Dummies Questions & Answers

deleting lines from a delimited files based on a 2nd file

I need a little help... I have a file with 3 fields, Time/Date, IP address, UniqueID I have a 2nd file of UniqueIDs. I want to either (which ever is easier): 1. delete entries in file 1 that have a UniqueID in file 2 2. create a new file with the fields from File 1, excluding the... (4 Replies)
Discussion started by: goldie363
4 Replies

5. Shell Programming and Scripting

Deleting the files based on the date's

I have to write one script which will delete the files in the below passion. If today is 17-Feb-2010 then the script delete only 17-JAN-2010 files from the directory. Could you please help me, How will I delete the files when the year is leap year, if today is 30th Mar 2010 then how will... (1 Reply)
Discussion started by: kandi.reddy
1 Replies

6. Shell Programming and Scripting

Deleting files based on their size

I have several files in a folder and I would like to delete the ones that do not contain all the required information (size) let say 1kb. Any ideas? (4 Replies)
Discussion started by: Xterra
4 Replies

7. UNIX for Dummies Questions & Answers

deleting files based on the suffix

how do we delete files based on the suffix??? (1 Reply)
Discussion started by: saggiboy10
1 Replies

8. Shell Programming and Scripting

Deleting lines based on a condition for a group of files

hi i have a set of similar files. i want to delete lines until certain pattern appears in those files. for a single file the following command can be used but i want to do it for all the files at a time since the number is in thousands. awk '/PATTERN/{i++}i' file (6 Replies)
Discussion started by: anurupa777
6 Replies

9. Shell Programming and Scripting

New files based off match or no match

Trying to match $2 in original_targets with $2 of new_targets . If the two numbers match exactly then a match.txt file is outputted using the information in the new_targets in the beginning 4 fields $1, $2, $3, $4 and value of $4 in the original_targets . If there is "No Match" then a no... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies
GONZUI-IMPORT(1)						   User Commands						  GONZUI-IMPORT(1)

NAME
gonzui-import - a tool to import contents from a gonzui DB SYNOPSIS
gonzui-import [OPTION] TARGET... DESCRIPTION
TARGET: directories, archives, packages (by apt) -a, --apt PACKAGE... use apt-get to get a source package --cvs REPOSITORY MODULE use cvs to get a source tree --svn REPOSITORY MODULE use svn to get a source tree --exclude=PATTERN exclude files matching PATTERN [(?-mix:~$|.bak$|CVS|.svn)] --no-utf8 don't convert files to UTF-8 --no-ABBREV don't index ABBREV files. (ex. --no-text) try --list-formats to see abbrev. list --list-archives list all supported archives --gonzuirc=FILE specify alternate run control file --dump-config dump configuration -d, --db-dir=DIR use DB directory DIR --db-cache=NUM use NUM megabytes of DB cache [5] --list-formats list all supported formats --help show this help message -q, --quiet suppress all normal output -v, --verbose output progress and statistics --version print version information and exit gonzui-import 1.3 December 2006 GONZUI-IMPORT(1)
All times are GMT -4. The time now is 12:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy