From: moonhkt on
Hi All
I am trying purge file again. This time base on file have backup copy
only.

Suppose moonhk is script file without extension and moonhkt.p is
program name.


Create file file purging.
touch moonhkt.p
touch -t 201005011234 moonhkt.p.20100501_1234icm
touch -t 201004281222 moonhkt.p.20100428_1222icm
touch -t 201004221222 moonhkt.p.20100422_1222icm
touch -t 201004201222 moonhkt.p.20100420_1222icm
touch moonhkt
touch -t 201005021222 moonhkt.20100502_1222icm
touch -t 201005021300 moonhkt.20100502_1300icm
touch -t 201004021300 moonhkt.20100402_1300icm

# Build list of file have backup
ls -lt *.*[0-9][0-9]_[0-9][0-9][0-9][0-9]icm | awk
' { n=split($9,FN,".")
if (n == 2) { print FN[1] }
else if (n == 3) { print FN[1] "." FN[2] }
else if (n == 4) { print FN[1] "." FN[2] "." FN[3]}
}' | sort -u > list.txt

# Purge file base on list.txt keep 2 backup


Base on list.txt, list of file have backup. I want keep 2 or 3 copy
moonhkt
moonhkt.p

I does not konw how to list moonhkt script for delete backup.

How to list moonhkt file and it backup ?
moonhkt
moonhkt.20100502_1300icm
moonhkt.20100402_1300icm
moonhkt.20100502_1222icm


moonhkt


From: Ed Morton on
On 5/7/2010 3:43 AM, moonhkt wrote:
> Hi All
> I am trying purge file again. This time base on file have backup copy
> only.
>
> Suppose moonhk is script file without extension and moonhkt.p is
> program name.
>
>
> Create file file purging.
> touch moonhkt.p
> touch -t 201005011234 moonhkt.p.20100501_1234icm
> touch -t 201004281222 moonhkt.p.20100428_1222icm
> touch -t 201004221222 moonhkt.p.20100422_1222icm
> touch -t 201004201222 moonhkt.p.20100420_1222icm
> touch moonhkt
> touch -t 201005021222 moonhkt.20100502_1222icm
> touch -t 201005021300 moonhkt.20100502_1300icm
> touch -t 201004021300 moonhkt.20100402_1300icm
>
> # Build list of file have backup
> ls -lt *.*[0-9][0-9]_[0-9][0-9][0-9][0-9]icm | awk
> ' { n=split($9,FN,".")
> if (n == 2) { print FN[1] }
> else if (n == 3) { print FN[1] "." FN[2] }
> else if (n == 4) { print FN[1] "." FN[2] "." FN[3]}
> }' | sort -u> list.txt

The above awk script seems to be splitting $9 at every "." and then printing the
resulting fields except the last separated by "."s. If all you want to do is get
rid of everything from the final "." to the end of the string, you may want
something like this instead:

sub(/\.[^.]*$/,"",$9); print $9

and you shouldn't use all-upper-case variable names - by convention that's for
built-in variables. Finally, you probably don't need the list sorted, but just
unique, so no need for the pipe to "sort -u":

ls -lt *.*[0-9][0-9]_[0-9][0-9][0-9][0-9]icm |
awk '{ $0=$9; sub(/\.[^.]*$/,"") } !f[$0]++' > list.txt

Regards,

Ed.

> # Purge file base on list.txt keep 2 backup
>
>
> Base on list.txt, list of file have backup. I want keep 2 or 3 copy
> moonhkt
> moonhkt.p
>
> I does not konw how to list moonhkt script for delete backup.
>
> How to list moonhkt file and it backup ?
> moonhkt
> moonhkt.20100502_1300icm
> moonhkt.20100402_1300icm
> moonhkt.20100502_1222icm
>
>
> moonhkt
>
>

From: moonhkt on
On 5月7日, 下午8時24分, Ed Morton <mortons...(a)gmail.com> wrote:
> On 5/7/2010 3:43 AM, moonhkt wrote:
>
>
>
> > Hi All
> > I am trying purge file again. This time base on file have backup copy
> > only.
>
> > Suppose moonhk is script file without extension and moonhkt.p is
> > program name.
>
> > Create file file purging.
> > touch moonhkt.p
> > touch -t 201005011234 moonhkt.p.20100501_1234icm
> > touch -t 201004281222 moonhkt.p.20100428_1222icm
> > touch -t 201004221222 moonhkt.p.20100422_1222icm
> > touch -t 201004201222 moonhkt.p.20100420_1222icm
> > touch moonhkt
> > touch -t 201005021222 moonhkt.20100502_1222icm
> > touch -t 201005021300 moonhkt.20100502_1300icm
> > touch -t 201004021300 moonhkt.20100402_1300icm
>
> > # Build list of file have backup
> > ls -lt *.*[0-9][0-9]_[0-9][0-9][0-9][0-9]icm  | awk
> > ' { n=split($9,FN,".")
> >         if (n == 2) { print FN[1] }
> >         else if (n == 3) { print FN[1] "." FN[2] }
> >         else if (n == 4) { print FN[1] "." FN[2] "." FN[3]}
> >     }' | sort -u>  list.txt
>
> The above awk script seems to be splitting $9 at every "." and then printing the
> resulting fields except the last separated by "."s. If all you want to do is get
> rid of everything from the final "." to the end of the string, you may want
> something like this instead:
>
>      sub(/\.[^.]*$/,"",$9); print $9
>
> and you shouldn't use all-upper-case variable names - by convention that's for
> built-in variables. Finally, you probably don't need the list sorted, but just
> unique, so no need for the pipe to "sort -u":
>
> ls -lt *.*[0-9][0-9]_[0-9][0-9][0-9][0-9]icm  |
> awk '{ $0=$9; sub(/\.[^.]*$/,"") } !f[$0]++' > list.txt
>
> Regards,
>
>       Ed.
>
> > # Purge file base on list.txt keep 2 backup
>
> > Base on  list.txt, list of file have backup. I want keep 2 or 3 copy
> > moonhkt
> > moonhkt.p
>
> > I does not konw how to list moonhkt script for delete backup.
>
> > How to list moonhkt file and it backup ?
> > moonhkt
> > moonhkt.20100502_1300icm
> > moonhkt.20100402_1300icm
> > moonhkt.20100502_1222icm
>
> > moonhkt

Hi Ed
How below work ?
!f[$0]++

I get the file name , Do you konw how to just list moonhkt and moont.
20100502_1300icm , moonhkt.20100402_1300icm and moonhkt.
20100502_1222icm
I want delete its backup file ?

#!/bin/ksh
# 2010/05/07
# Ubuntu, ls -lt just 8 column
ls -lt *.*[0-9][0-9]_[0-9][0-9][0-9][0-9]icm |
awk '{ $0=$8; sub(/\.[^.]*$/,"") } !f[$0]++'



moonhk(a)moonhk:~/temp$ xpurge.ksh
moonhkt.ksh
moonhkt
moonhkt.p
moonhk(a)moonhk:~/temp$



moonhkt