awk question

Bill Campbell freebsd at celestial.com
Tue Mar 6 00:42:11 UTC 2007


On Mon, Mar 05, 2007, Gary Kline wrote:
>
>	Guys,
>
>	Having found $9 , how do I /bin/rm it (using system()--yes??)
>	in an awk one-liner?
>
>	I'm trying to remove from packages from long ago and find and
>	print them with
>
>	ls -lt | awk '{if ($8 == 2006) print $9}';
>
>	but what I want to remove the file pointed at by $9.  I've tried
>	FILE=ARGV[9]; and using FILE within my system() call, but no-joy.
>	What's the magic here?

A better way to do this might be to use find and xargs.  The
command below would remove all files under the current directory
that haven't been modified in the 360 days.

	find . -type f -mtime +360 -print0 | xargs -0 rm

If you don't want it to go into subdirectories:

	find . -maxdepth 1 -type f -mtime +360 -print0 | xargs -0 rm

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``Anyone who thinks Microsoft never does anything truly innovative isn't
paying attention to the part of the company that pushes the state of
its art: Microsoft's legal department.'' 
   --Ed Foster, InfoWorld Gripe Line columnist


More information about the freebsd-questions mailing list