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
# 8  
Old 04-06-2008
Many thanks. It works a treat as suggested by you.

Thanks mate. Much appreciated
# 9  
Old 04-07-2008
Code:
for i in `ls -l a* | awk 'BEGIN{FS="_"}{print $NF}'`
do
	if [ $i -le $1 ]
	then
		gzip "a_"$i
	fi
done

# 10  
Old 04-07-2008
Quote:
Originally Posted by era
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.


Hello,

not sure if i am doing anything wrong.. but all the files are getting gzipped. Can someone help

-rw-r----- 1 oraukp dba 93237760 Apr 6 19:51 UKPP1_1_994_639156890.arc
-rw-r----- 1 oraukp dba 64181248 Apr 7 02:10 UKPP1_1_995_639156890.arc
-rw-r----- 1 oraukp dba 2048 Apr 7 02:10 UKPP1_1_996_639156890.arc
-rw-r----- 1 oraukp dba 86528 Apr 7 02:11 UKPP1_1_997_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 7 02:11 UKPP1_1_998_639156890.arc
-rw-r----- 1 oraukp dba 1024 Apr 7 02:11 UKPP1_1_999_639156890.arc
-rw-r----- 1 oraukp dba 115200 Apr 7 02:12 UKPP1_1_1000_639156890.arc
-rw-r----- 1 oraukp dba 14367744 Apr 7 05:00 UKPP1_1_1001_639156890.arc
-rw-r----- 1 oraukp dba 587776 Apr 7 05:00 UKPP1_1_1002_639156890.arc
-rw-r----- 1 oraukp dba 38299648 Apr 7 12:00 UKPP1_1_1003_639156890.arc
-rw-r----- 1 oraukp dba 13824 Apr 7 12:01 UKPP1_1_1004_639156890.arc
drwxr-xr-x 2 oraukp dba 5120 Apr 7 12:10 .
drwxr-xr-x 4 oraukp dba 96 Apr 7 12:24 ..
[oraukp] "gbwxvcsmbc1:"/gbwaapsmbp1/ora01/app/oracle/admin/UKPP1/arch:
UKPP1> COUNT=999
[oraukp] "gbwxvcsmbc1:"/gbwaapsmbp1/ora01/app/oracle/admin/UKPP1/arch:
UKPP1> ls | sed -e "/UKPP1_1_${COUNT}_/q" | xargs gzip -9
[oraukp] "gbwxvcsmbc1:"/gbwaapsmbp1/ora01/app/oracle/admin/UKPP1/arch:
UKPP1> ls -lart
total 51738
-rw-r----- 1 oraukp dba 24172665 Apr 6 19:51 UKPP1_1_994_639156890.arc.gz
-rw-r----- 1 oraukp dba 15265903 Apr 7 02:10 UKPP1_1_995_639156890.arc.gz
-rw-r----- 1 oraukp dba 549 Apr 7 02:10 UKPP1_1_996_639156890.arc.gz
-rw-r----- 1 oraukp dba 219 Apr 7 02:11 UKPP1_1_998_639156890.arc.gz
-rw-r----- 1 oraukp dba 27022 Apr 7 02:11 UKPP1_1_997_639156890.arc.gz
-rw-r----- 1 oraukp dba 223 Apr 7 02:11 UKPP1_1_999_639156890.arc.gz
-rw-r----- 1 oraukp dba 27332 Apr 7 02:12 UKPP1_1_1000_639156890.arc.gz
-rw-r----- 1 oraukp dba 3632384 Apr 7 05:00 UKPP1_1_1001_639156890.arc.gz
-rw-r----- 1 oraukp dba 143206 Apr 7 05:00 UKPP1_1_1002_639156890.arc.gz
-rw-r----- 1 oraukp dba 9693938 Apr 7 12:00 UKPP1_1_1003_639156890.arc.gz
-rw-r----- 1 oraukp dba 4766 Apr 7 12:01 UKPP1_1_1004_639156890.arc.gz
drwxr-xr-x 4 oraukp dba 96 Apr 7 12:24 ..
drwxr-xr-x 2 oraukp dba 5120 Apr 7 12:26 .
# 11  
Old 04-07-2008
Code:
awk 'BEGIN{
 s="zip backup " 
 printf "Which number? eg(106): "
 getline number < "-"
}
{
  split(FILENAME,f,"_")
  if ( f[3] < number ) {
   s=s" "FILENAME
  }
}
END {
 print s
 #system(s) #uncomment to use.
}' UKP*

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