Delete all files up to a sequence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete all files up to a sequence
# 1  
Old 04-06-2008
Delete all files up to a sequence

All,

Please can you help me with this ?

I have a requirement to compress the files older than a sequence number.

Say the directory has the following files

a_101
a_102
a_103
a_104
a_105
a_106
a_107
a_108

I would like to compress all files based on a number i supply. IE. if i get 106, i would like to compress everything upto 105. How do it achieve this please ? Files are usually in ascending order of time.

Thanks in advance.
# 2  
Old 04-06-2008
Code:
ls or whatever | sed -e "/_$number$/q" | xargs gzip -9

# 3  
Old 04-06-2008
Thanks very much. Also, how do i get the middle part in this file name ? ie. i need to extract 989. And that would grow to 1000 or 100000. So, what command can i use other than cut

JHPP1_1_989_639156890.arc
# 4  
Old 04-06-2008
Thank you. But that command compressed everything.. Not something i was looking.


UKPP1> ls
UKPP1_1_983_639156890.arc UKPP1_1_985_639156890.arc UKPP1_1_987_639156890.arc
UKPP1_1_984_639156890.arc UKPP1_1_986_639156890.arc
[oraukp] "gbwxvcsmbc1:"/gbwaapsmbp1/oraarch/oradata/UKPP1/arch/test:
UKPP1> ls | sed -e "/UKPP1_1_$number$/q" | xargs gzip -9
[oraukp] "gbwxvcsmbc1:"/gbwaapsmbp1/oraarch/oradata/UKPP1/arch/test:
UKPP1> ls -lart

[oraukp] "gbwxvcsmbc1:"/gbwaapsmbp1/oraarch/oradata/UKPP1/arch/test:
UKPP1> ls
UKPP1_1_983_639156890.arc.gz UKPP1_1_986_639156890.arc.gz
UKPP1_1_984_639156890.arc.gz UKPP1_1_987_639156890.arc.gz
UKPP1_1_985_639156890.arc.gz
# 5  
Old 04-06-2008
You need to plug in the particular $number you want.

The regular expression /_$number$/ with number=999 turns into /_999$/ which matches 999 at end of line, if immediately preceded by an underscore.

If you don't want end of line, construct a regular expression which matches the context you want. Superficially, something like /_$number_/ would seem to match the file names you gave as examples.

For playing around, maybe use "echo gzip" instead of just "gzip" to see what would happen, without making it actually happen.

Last edited by era; 04-06-2008 at 07:55 AM.. Reason: Hard-to-understand typo
# 6  
Old 04-06-2008
Hello Thanks very much.. I tired it as you said but still no luck. I was expecting it to compress every file older than 987 ( NUM set to 987) but it did that for only one file


UKPP1> ls | sed -e "/UKPP1_1_$NUM_/q" | xargs gzip -9
gzip: test is a directory -- ignored
[oraukp] "gbwxvcsmbc1:"/gbwaapsmbp1/oraarch/oradata/UKPP1/arch:
UKPP1> ls -lart
total 2228907
drwxr-xr-x 3 oraukp dba 96 Mar 12 10:10 ..
-rw-r----- 1 oraukp dba 330752 Mar 31 19:51 UKPP1_1_890_639156890.arc
-rw-r----- 1 oraukp dba 592896 Mar 31 19:51 UKPP1_1_894_639156890.arc
-rw-r----- 1 oraukp dba 1168384 Mar 31 19:51 UKPP1_1_891_639156890.arc
-rw-r----- 1 oraukp dba 459264 Mar 31 19:51 UKPP1_1_897_639156890.arc
-rw-r----- 1 oraukp dba 865792 Mar 31 19:51 UKPP1_1_892_639156890.arc
-rw-r----- 1 oraukp dba 1816058 Mar 31 19:51 UKPP1_1_888_639156890.arc.gz
-rw-r----- 1 oraukp dba 3683840 Mar 31 19:51 UKPP1_1_889_639156890.arc
-rw-r----- 1 oraukp dba 5373952 Mar 31 19:51 UKPP1_1_893_639156890.arc
-rw-r----- 1 oraukp dba 56283136 Mar 31 19:51 UKPP1_1_896_639156890.arc
-rw-r----- 1 oraukp dba 93237760 Mar 31 19:51 UKPP1_1_895_639156890.arc
-rw-r----- 1 oraukp dba 3941888 Mar 31 19:59 UKPP1_1_898_639156890.arc
-rw-r----- 1 oraukp dba 3380736 Mar 31 20:01 UKPP1_1_899_639156890.arc
-rw-r----- 1 oraukp dba 1024 Mar 31 20:05 UKPP1_1_900_639156890.arc
-rw-r----- 1 oraukp dba 5167616 Mar 31 20:34 UKPP1_1_901_639156890.arc
-rw-r----- 1 oraukp dba 706560 Mar 31 20:39 UKPP1_1_902_639156890.arc
-rw-r----- 1 oraukp dba 117760 Mar 31 20:44 UKPP1_1_903_639156890.arc
-rw-r----- 1 oraukp dba 1024 Mar 31 20:48 UKPP1_1_904_639156890.arc
-rw-r----- 1 oraukp dba 137216 Mar 31 20:50 UKPP1_1_905_639156890.arc
-rw-r----- 1 oraukp dba 1290752 Mar 31 20:59 UKPP1_1_906_639156890.arc
-rw-r----- 1 oraukp dba 1133568 Mar 31 21:02 UKPP1_1_907_639156890.arc
-rw-r----- 1 oraukp dba 37888 Mar 31 21:03 UKPP1_1_908_639156890.arc
-rw-r----- 1 oraukp dba 1024 Mar 31 21:05 UKPP1_1_909_639156890.arc
-rw-r----- 1 oraukp dba 93237760 Mar 31 22:31 UKPP1_1_910_639156890.arc
-rw-r----- 1 oraukp dba 93237760 Mar 31 22:32 UKPP1_1_911_639156890.arc
-rw-r----- 1 oraukp dba 80937472 Apr 1 02:12 UKPP1_1_912_639156890.arc
-rw-r----- 1 oraukp dba 44544 Apr 1 02:13 UKPP1_1_913_639156890.arc
-rw-r----- 1 oraukp dba 109056 Apr 1 02:15 UKPP1_1_914_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 1 02:15 UKPP1_1_915_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 1 02:15 UKPP1_1_916_639156890.arc
-rw-r----- 1 oraukp dba 157184 Apr 1 02:15 UKPP1_1_917_639156890.arc
-rw-r----- 1 oraukp dba 12142080 Apr 1 05:00 UKPP1_1_918_639156890.arc
-rw-r----- 1 oraukp dba 686592 Apr 1 05:00 UKPP1_1_919_639156890.arc
-rw-r----- 1 oraukp dba 44063232 Apr 1 12:00 UKPP1_1_920_639156890.arc
-rw-r----- 1 oraukp dba 1067008 Apr 1 12:01 UKPP1_1_921_639156890.arc
-rw-r----- 1 oraukp dba 93231616 Apr 1 14:14 UKPP1_1_922_639156890.arc
-rw-r----- 1 oraukp dba 65203712 Apr 1 16:00 UKPP1_1_923_639156890.arc
-rw-r----- 1 oraukp dba 2560 Apr 1 16:00 UKPP1_1_924_639156890.arc
-rw-r----- 1 oraukp dba 93295616 Apr 1 22:30 UKPP1_1_925_639156890.arc
-rw-r----- 1 oraukp dba 93237760 Apr 1 22:32 UKPP1_1_926_639156890.arc
-rw-r----- 1 oraukp dba 83577344 Apr 2 02:11 UKPP1_1_927_639156890.arc
-rw-r----- 1 oraukp dba 2048 Apr 2 02:11 UKPP1_1_928_639156890.arc
-rw-r----- 1 oraukp dba 186368 Apr 2 02:12 UKPP1_1_929_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 2 02:12 UKPP1_1_930_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 2 02:12 UKPP1_1_931_639156890.arc
-rw-r----- 1 oraukp dba 2560 Apr 2 02:13 UKPP1_1_932_639156890.arc
-rw-r----- 1 oraukp dba 15537664 Apr 2 05:00 UKPP1_1_933_639156890.arc
-rw-r----- 1 oraukp dba 4608 Apr 2 05:01 UKPP1_1_934_639156890.arc
-rw-r----- 1 oraukp dba 59206144 Apr 2 12:00 UKPP1_1_935_639156890.arc
-rw-r----- 1 oraukp dba 269312 Apr 2 12:01 UKPP1_1_936_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 2 15:13 UKPP1_1_938_639156890.arc
-rw-r----- 1 oraukp dba 45271552 Apr 2 15:13 UKPP1_1_937_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 2 15:13 UKPP1_1_939_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 2 15:13 UKPP1_1_940_639156890.arc
-rw-r----- 1 oraukp dba 3918848 Apr 2 16:00 UKPP1_1_941_639156890.arc
-rw-r----- 1 oraukp dba 2178048 Apr 2 16:00 UKPP1_1_942_639156890.arc
-rw-r----- 1 oraukp dba 93237760 Apr 2 22:14 UKPP1_1_943_639156890.arc
-rw-r----- 1 oraukp dba 93237760 Apr 2 22:31 UKPP1_1_944_639156890.arc
-rw-r----- 1 oraukp dba 92831232 Apr 3 02:11 UKPP1_1_945_639156890.arc
-rw-r----- 1 oraukp dba 2560 Apr 3 02:11 UKPP1_1_946_639156890.arc
-rw-r----- 1 oraukp dba 183808 Apr 3 02:13 UKPP1_1_947_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 3 02:13 UKPP1_1_948_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 3 02:13 UKPP1_1_949_639156890.arc
-rw-r----- 1 oraukp dba 3072 Apr 3 02:13 UKPP1_1_950_639156890.arc
-rw-r----- 1 oraukp dba 15377408 Apr 3 05:00 UKPP1_1_951_639156890.arc
-rw-r----- 1 oraukp dba 614400 Apr 3 05:01 UKPP1_1_952_639156890.arc
-rw-r----- 1 oraukp dba 42259968 Apr 3 12:00 UKPP1_1_953_639156890.arc
-rw-r----- 1 oraukp dba 1185792 Apr 3 12:01 UKPP1_1_954_639156890.arc
-rw-r----- 1 oraukp dba 21061120 Apr 3 16:00 UKPP1_1_955_639156890.arc
-rw-r----- 1 oraukp dba 2048 Apr 3 16:00 UKPP1_1_956_639156890.arc
-rw-r----- 1 oraukp dba 95861248 Apr 3 22:30 UKPP1_1_957_639156890.arc
-rw-r----- 1 oraukp dba 93230080 Apr 3 22:32 UKPP1_1_958_639156890.arc
-rw-r----- 1 oraukp dba 92155392 Apr 4 02:12 UKPP1_1_959_639156890.arc
-rw-r----- 1 oraukp dba 13824 Apr 4 02:12 UKPP1_1_960_639156890.arc
-rw-r----- 1 oraukp dba 178688 Apr 4 02:14 UKPP1_1_961_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 4 02:14 UKPP1_1_962_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 4 02:14 UKPP1_1_963_639156890.arc
-rw-r----- 1 oraukp dba 1536 Apr 4 02:14 UKPP1_1_964_639156890.arc
-rw-r----- 1 oraukp dba 16184320 Apr 4 05:00 UKPP1_1_965_639156890.arc
-rw-r----- 1 oraukp dba 6656 Apr 4 05:01 UKPP1_1_966_639156890.arc
-rw-r----- 1 oraukp dba 31097344 Apr 4 10:57 UKPP1_1_967_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 4 11:32 UKPP1_1_968_639156890.arc
-rw-r----- 1 oraukp dba 17374720 Apr 4 11:32 UKPP1_1_969_639156890.arc
-rw-r----- 1 oraukp dba 50688 Apr 4 11:32 UKPP1_1_970_639156890.arc
-rw-r----- 1 oraukp dba 6469632 Apr 4 12:00 UKPP1_1_971_639156890.arc
-rw-r----- 1 oraukp dba 912384 Apr 4 12:01 UKPP1_1_972_639156890.arc
-rw-r----- 1 oraukp dba 23035392 Apr 4 16:00 UKPP1_1_973_639156890.arc
-rw-r----- 1 oraukp dba 2048 Apr 4 16:01 UKPP1_1_974_639156890.arc
-rw-r----- 1 oraukp dba 97453056 Apr 4 22:31 UKPP1_1_975_639156890.arc
-rw-r----- 1 oraukp dba 93237760 Apr 4 22:32 UKPP1_1_976_639156890.arc
-rw-r----- 1 oraukp dba 93237760 Apr 5 03:00 UKPP1_1_977_639156890.arc
-rw-r----- 1 oraukp dba 1119232 Apr 5 03:11 UKPP1_1_978_639156890.arc
-rw-r----- 1 oraukp dba 1536 Apr 5 03:11 UKPP1_1_979_639156890.arc
-rw-r----- 1 oraukp dba 88064 Apr 5 03:12 UKPP1_1_980_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 5 03:12 UKPP1_1_981_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 5 03:12 UKPP1_1_982_639156890.arc
-rw-r----- 1 oraukp dba 5120 Apr 5 03:12 UKPP1_1_983_639156890.arc
-rw-r----- 1 oraukp dba 45633536 Apr 5 06:10 UKPP1_1_984_639156890.arc
-rw-r----- 1 oraukp dba 2048 Apr 5 06:10 UKPP1_1_985_639156890.arc
-rw-r----- 1 oraukp dba 277504 Apr 5 10:02 UKPP1_1_987_639156890.arc
-rw-r----- 1 oraukp dba 18826752 Apr 5 10:02 UKPP1_1_986_639156890.arc
-rw-r----- 1 oraukp dba 5128192 Apr 5 10:02 UKPP1_1_988_639156890.arc
-rw-r----- 1 oraukp dba 14983680 Apr 5 12:00 UKPP1_1_989_639156890.arc
-rw-r----- 1 oraukp dba 1068032 Apr 5 12:01 UKPP1_1_990_639156890.arc
-rw-r----- 1 oraukp dba 20111872 Apr 5 16:00 UKPP1_1_991_639156890.arc
-rw-r----- 1 oraukp dba 712192 Apr 5 16:00 UKPP1_1_992_639156890.arc
-rw-r----- 1 oraukp dba 93342720 Apr 6 03:00 UKPP1_1_993_639156890.arc
drwxr-xr-x 2 oraukp dba 1024 Apr 6 11:39 test
drwxr-xr-x 3 oraukp dba 5120 Apr 6 11:43 .
[oraukp] "gbwxvcsmbc1:"/gbwaapsmbp1/oraarch/oradata/UKPP1/arch:
UKPP1>
UKPP1> echo $NUM
987
# 7  
Old 04-06-2008
Sorry, typical newbie mistake: it's looking for "$NUM_" and finding it undefined. You need to say "${NUM}_" in order to show where the variable name ends and the context string starts.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add sequence number to files

Hi I am having files in my dir ,some times it vary ,i need to assign sequence number with gunzip the file name .Please advise ex: file1.gz file1111.gz file11111.gz file1111111.gz expecting out output file_1 file1111_2 file1111111_3 i written this script ,its not working what i... (3 Replies)
Discussion started by: mohan705
3 Replies

2. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

3. Shell Programming and Scripting

Case script to get missing sequence among files

I want to use case statement to find the range of missing sequence in my directory which it has some few ( dat & DAT ) files my directory /home/arm/my_folder/20130428 contains : f01_201304280000.DAT f01_201304280001.DAT f01_201304280003.DAT f02_201304280000.dat f02_201304280002.dat... (2 Replies)
Discussion started by: arm
2 Replies

4. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

5. Shell Programming and Scripting

New sequence nos to be added in new files

Hi All, Please help me in below request. Got multiple files in a dir ex: /os . from each file need to filter based upon first field (field only has 1,2,3 or 4) and then put it in different files based on the Field 1. But need to generate a sequence while inserting and the sequence number needs... (1 Reply)
Discussion started by: rdakshn
1 Replies

6. Shell Programming and Scripting

print out missing files in a sequence

Hello all, I have several directories with a sequence of files like this IM-0001-0001.dcm IM-0001-0002.dcm IM-0001-0003.dcm IM-0001-0004.dcm IM-0001-0005.dcm I would like to print out the name of the file that is missing. I currently have the following ineffecient way to do this... (4 Replies)
Discussion started by: avatar_007
4 Replies

7. Shell Programming and Scripting

ls all files in sequence. How to?

Hi, all: Newbie questions: For example, if I have 6 files, respectively named as: How to "ls" all files in sequence of two ways? 1) The first way is according to the sequence of the natural number. Say, the same sequence as shown as they are given. 2) The second way is default... (2 Replies)
Discussion started by: jiapei100
2 Replies

8. Shell Programming and Scripting

perl merge two files by the time sequence

Hi Guys, i have two files: fileA: 20090611 00:00:11 20090611 00:00:11 20090611 00:00:24 20090611 00:01:10 20090611 07:13:00 fileB: 20090611 00:00:01 20090611 00:00:12 20090611 00:00:24 20090611 00:01:12 20090611 09:13:00 want to make two files into a single file, but follow the... (14 Replies)
Discussion started by: jimmy_y
14 Replies

9. Shell Programming and Scripting

script to touch a sequence of files

Hi, My requirement is i need to touch a sequence of files like touch a touch b touch c now i need the script in a way that checks if all files are touched or not. if any file say b is not touched then i should get this notification. Please suggest as i am new to unix (2 Replies)
Discussion started by: sussane
2 Replies

10. UNIX for Dummies Questions & Answers

Rename Files in sequence

I have a bunch of files below in some directory /home/tmp: abc.txt def.txt ghi.txt And I want to rename them with sequence as their extension (in the format 00# see below): abc.001 def.002 ghi.003 I need some help with this and below is a basic code structure to get... (3 Replies)
Discussion started by: ChicagoBlues
3 Replies
Login or Register to Ask a Question