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

Geoffrey esoteric at 3times25.net
Sun Mar 19 07:54:21 EST 2006


Paul Cartwright wrote:
> On Sat March 18 2006 12:50 pm, Courtney Thomas wrote:
>> I should ask though, how'd you come up with "-f 9" in cut ?
>>
>> Courtney
>>
>> Joe Knapka wrote:
>>> Hi Courtney,
>>>
>>> This worked for me just now, to interactively
>>> remove files modified on March 15:
>>>
>>> rm -i $(ls -l | grep 'Mar 15' | cut -d ' ' -f 9)
> 
> cut -d means delimited by , ' ' means the delimiting factor is a space
> -f 9 means the 9th field
> 
> so I'm guessing the 9th field would be the name of the file from this 
> ls -l output..
> 
> -rwxr-xr-x   1 root root       6552 2005-09-12 19:47 zvbi-chains

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.

awk is the toy you want:

rm -i $(ls -l | awk '/Mar 15/ {print $NF})

awk's default delimiter is whitespace so tabs, contiguous whitespace 
will both be handled as delimiters.

-- 
Until later, Geoffrey



More information about the Ale mailing list