nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Comparing filename-substrings and remove unnecessary files

This is a discussion on Comparing filename-substrings and remove unnecessary files within the Shell scripting forums, part of the Development/Scripting category; hi folks... i have to write a sript that removes unnecessary backup-files. iam new to shell scripting so please be ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-26-2008, 06:05 PM
Junior Member
User
 
Join Date: May 2008
My distro: Aix 5.3
Posts: 1
Rep Power: 0
cypher82 is on a distinguished road
Question Comparing filename-substrings and remove unnecessary files

hi folks...
i have to write a sript that removes unnecessary backup-files.
iam new to shell scripting so please be patient with me. and no its not homework
these files look like "javacore303330.1209029863.txt" where the first number is the PID and the second is the timestamp. so there can be a lot javacores with the same PID but i need only the 2 latest ones.
before:
Code:
javacore479430.1208522264.txt
javacore479430.1208522097.txt
javacore479430.1208521935.txt
javacore479430.1208521772.txt
javacore540754.1209554863.txt
javacore540754.1209551357.txt
javacore540754.1209551130.txt
after:
Code:
javacore479430.1208522264.txt
javacore479430.1208522097.txt
javacore540754.1209554863.txt
javacore540754.1209551357.txt
My basic approach looks like that:
Code:
#comparing every file with every file
#and inc. the counter
for ((  i = 1;  i <= ${number_of_files};  i++  ))
do     for ((  j = 1;   j<= ${number_of_files-1};  j++  ))
         do
             if (pid_file.i = pid_file.j+1)
            and if counter<=2
            do counter++
            else remove_file file.j
my attempt:
Code:
#pid >> list
ls -t|grep javacore |cut -c 9-14  >> /home/user/list.txt
chmod a+x /home/user/list.txt

number_of_files=$(cat "/home/de151738/liste.txt" | wc -w)

#now the tough part
for ((  i = 1;  i <= ${number_of_files};  i++  ))
do     for ((  j = 1;   j<= ${number_of_files-1};  j++  ))
         do
 #?        if {list.line.i = list.line.j}
 #           and if counter<=2 
 #          do   counter++
 #        else rm file.j
If anybody has some advice I would be glad. Maybe my basic approach could be already wrong
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-28-2008, 12:53 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 910
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Use find command
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Triming a filename? lone_wolfy Shell scripting 5 03-20-2008 10:43 PM
HPUX Unix comparing 2 large files line by line raj HP-UX 1 02-11-2008 05:20 PM
Grep and remove files Linux software 1 01-05-2006 06:25 PM
Script to remove executable files sweta Shell scripting 4 03-12-2005 01:21 PM
Comparing MySQL Performance vivek The Hangout 0 02-11-2005 04:10 PM


All times are GMT +5.5. The time now is 05:27 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36