This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Couple of scripts to remove duplicate packages


Hi,
I have a habit of keeping cygwin packages on my computer and updating them from time to time using setup.exe. This saves me time when I need to install on another computer.
This creates a problem of old versions of packages accumulating in my download directory. I used to remove them by hand but that is a time consuming process. Finally I wrote an awk script to help me deal with the problem. And just for kicks I added a shell wrapper :).


Attached are the scripts. I hope they could be useful to someone else.
I am sure they can be improved but they have been useful to me as is.

Thanks,
Alex
#! /bin/awk
BEGIN { \
  last_pkg = "";
  last_date = 0;
  last_dir = "";
  last_pkg_name = "";
  cmd = "find release -type f -printf '%h %f %TY%Tm%Td\n'";
  while(( cmd | getline ) > 0)
    { 
      dir = $1;
      pkg = $2;
      date = $3;
      count = split(dir, part, "/");
      if( last_pkg_name == part[count] ){
	if( date < last_date ){
	  print dir "/" pkg;
	  continue;
	}else{
	  print last_dir "/" last_pkg;
	}
      }
      last_pkg = pkg;
      last_date = date;
      last_dir = dir;
      last_pkg_name = part[count];
    }
  close(cmd);
}
#! /bin/bash
# Version of cyg-remove-dups in bash, just for kicks. Still uses awk and find
# awk is used in a normal way. Trick is to pass program to it with the data
# on stdin.
find release -type f -printf "%h %f %TY%Tm%Td\n"  | \
awk -- '
BEGIN { \
  last_pkg = "";
  last_date = 0; 
  last_dir = "";
  last_pkg_name = ""; 
}
{
  dir = $1;
  pkg = $2;
  date = $3;
  count = split(dir, part, "/");
  if( last_pkg_name == part[count] ){
    if( date < last_date ){
       print dir "/" pkg;
       next;
    }else{
        print last_dir "/" last_pkg;
    }
  }
  last_pkg = pkg;
  last_date = date;
  last_dir = dir;
  last_pkg_name = part[count];
}
'
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]