Find command to delete a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find command to delete a pattern
# 1  
Old 10-25-2011
Find command to delete a pattern

Hi all
i have a directory where it has files as shown below.Using find command how can i delete files which were modified more than 20 days ago and having the pattern jnhld15231 or jnhld15232.
Code:
find ./ -name "jnhld15231^" -type f -mtime +20  -exec rm {} \;
find ./ -name "jnhld15232^" -type f -mtime +20 -exec rm {} \;

how can i club the above two commands together
Code:
-rw-rw-r--  1 nh00000 etl_dev 503 Oct 16 05:22 jnhld15231_DIM_COUNT_SUMMARY_2011-10-16_052233.txt
-rw-rw-r--  1 nh00000 etl_dev 581 Oct 16 05:22 jnhld15231_FACT_COUNT_SUMMARY_2011-10-16_052233.txt
-rw-rw-r--  1 nh00000 etl_dev 503 Oct 16 05:22 jnhld15231_DIM_COUNT_SUMMARY_2011-10-16_052244.txt
-rw-rw-r--  1 nh00000 etl_dev 581 Oct 16 05:22 jnhld15231_FACT_COUNT_SUMMARY_2011-10-16_052244.txt
-rw-rw-r--  1 nh00000 etl_dev 503 Oct 16 05:22 jnhld15232_DIM_COUNT_SUMMARY_2011-10-16_052256.txt
-rw-rw-r--  1 nh00000 etl_dev 581 Oct 16 05:23 jnhld15232_FACT_COUNT_SUMMARY_2011-10-16_052256.txt
-rw-rw-r--  1 nh00000 etl_dev   0 Oct 16 05:23 jnhld15232_DIM_ROW_ERROR_2011-10-16.txt
-rw-rw-r--  1 nh00000 etl_dev 503 Oct 16 05:23 jnhld15232_DIM_COUNT_SUMMARY_2011-10-16_052306.txt
-rw-rw-r--  1 nh00000 etl_dev   0 Oct 16 05:23 jnhld15232_FACT_ROW_ERROR_2011-10-16.txt
-rw-rw-r--  1 nh00000 etl_dev 581 Oct 16 05:23 jnhld15232_FACT_COUNT_SUMMARY_2011-10-16_052306.txt
-rw-rw-r--  1 nh00000 etl_dev   0 Oct 16 05:50 jnhld15231_DIM_ROW_ERROR_2011-10-16.txt
-rw-rw-r--  1 nh00000 etl_dev 503 Oct 16 05:50 jnhld15231_DIM_COUNT_SUMMARY_2011-10-16_055016.txt
-rw-rw-r--  1 nh00000 etl_dev   0 Oct 16 05:50 jnhld15231_FACT_ROW_ERROR_2011-10-16.txt
-rw-rw-r--  1 nh00000 etl_dev 581 Oct 16 05:50 jnhld15231_FACT_COUNT_SUMMARY_2011-10-16_055016.txt


Last edited by Franklin52; 10-25-2011 at 05:46 AM.. Reason: Please use code tags, thank you
# 2  
Old 10-25-2011
find

Hi,

Try this one,

Code:
find ./ -name "jnhld1523[1-2]*" -type f -mtime +20 -exec rm {} \;

Cheers,
RangaSmilie
# 3  
Old 10-25-2011
thanks a lot dude
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find to delete lines with pattern and even or odd number

In the below directory I am trying to delete all lines with a .bam extention that have the pattern IonCode_ followed by an even number. I am also trying to delete all lines with a .fastq extention that have the pattern IonCode_ followed by an odd number. I was going to use find but can see all... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

Pattern find and delete

Hi Team, Could someone please help me on this .. While doing my day to day activity I use to delete manually the repeated ones .. For example 05 & 06 are my hosts.. Now I need to print only 05 and 06, 05-06 is not required. This is how I generate my report daily .. DBG-STG1-05... (5 Replies)
Discussion started by: Nallachand
5 Replies

3. Shell Programming and Scripting

sed command to delete a pattern in a file

Hi Everyone, I have an unusual requirement. Here is where i am stuck for sometime now... I have this text file.. lets say .. output.sql... it has lot of entries... here below is part of the entry... .. . . . . . . . . . . . . . . . .... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Shell Programming and Scripting

Multiple pattern find and delete line

I have a file # cat /tmp/user_find.txt /home/user/bad_link1 /home/user/www /home/user/mail /home/user/access_logs /home/user/bad_link2 I need to delete lines where there are patterns /home/user/www, /home/user/mail and /home/user/access_logs. I used below method, but its throwing error... (8 Replies)
Discussion started by: anil510
8 Replies

5. Shell Programming and Scripting

Find pattern a delete previous 5 lines

Hi guys, i have the follow problem i need to delete 10 row before the pattern and 1 after and the pattern row itself. file looks like: frect 9.8438 25.8681 10.625 25 . dynprop \ (# \ (call fox_execute(__self))) \ (FOX_VAR_29 \ ... (4 Replies)
Discussion started by: EjjE
4 Replies

6. Shell Programming and Scripting

sed to find pattern and delete line before and after

I have the following file: line1 line2 MATCH line3 line4 I need to find the pattern, "MATCH" and delete the line before and after MATCH. So the result should be line1 MATCH lline4 I have to use sed because it is the only utility that is common across my environments. I... (1 Reply)
Discussion started by: craftereric
1 Replies

7. Shell Programming and Scripting

awk/sed/perl command to delete specific pattern and content above it...

Hi, Below is my input file: Data: 1 Length: 20 Got result. Data: 2 Length: 30 No result. Data: 3 Length: 20 (7 Replies)
Discussion started by: edge_diners
7 Replies

8. Shell Programming and Scripting

sed find matching pattern delete next line

trying to use sed in finding a matching pattern in a file then deleting the next line only .. pattern --> <ad-content> I tried this but it results are not what I wish sed '/<ad-content>/{N;d;}' akv.xml > akv5.xml ex, <Celebrant2First>Mickey</Celebrant2First> <ad-content> Minnie... (2 Replies)
Discussion started by: aveitas
2 Replies

9. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

10. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies
Login or Register to Ask a Question