[ale] THANKS to all who replied to "ls -rt | rm -i" problem, BUT...ATTN:JoeKnapka

Geoffrey esoteric at 3times25.net
Sun Mar 19 13:22:43 EST 2006


Paul Cartwright wrote:
> On Sun March 19 2006 7:54 am, Geoffrey wrote:
>> I don't believe that's going to work, because cut does not expand
>> the single delimiter character to multiples.  That is if you have 3
>> spaces together, cut will have the first space as a field, the 2nd
>> as a delimiter the third as the next field.
>>
> I agree that fields won't do it, but cutting by character will, maybe?
> 
> 
>> awk is the toy you want:
>>
>> rm -i $(ls -l | awk '/Mar 15/ {print $NF})
> 
> I'm not going to play around with awk and rm :)


Well, I've played around with it a bit, but it's a bit uglier then I 
expected.  There's no easy way to escape the spaces in a file name with 
awk in such a way that 'rm -i' will be happy.  I can properly display 
filenames with spaces in them as follows:


ls -l |awk '/Mar 15/ {
     if (NF == 9) { print $NF }
     else {
         for (i=9; i<=(NF - 1); i++) {
             printf "%s ", $i; } printf "%s\n", $NF;
     }
}'

Problem is, 'rm -i' sees the filename as two different files when passed 
as in 'rm -i $(...)'

I can pipe the output of the script to xargs, but xargs doesn't wait for 
a response to rm -i, thus that doesn't work either.

-- 
Until later, Geoffrey



More information about the Ale mailing list