[vox-tech] Regular expression help

Harold Lee harold at hotelling.net
Wed Jun 30 15:16:52 PDT 2010


Take 2:

perl -n -e 'chomp; if(/([^ ]+)$/) { print "rm -f $1\n"; }' < files-to-delete.txt

-n will loop over the input lines like -p but it won't echo the input
lines. Chomp will remove the newlines. Adding the "if" makes sure we
don't print "rm -f" for empty lines or lines that don't match.

Then you have your rm commands and you can scan them for correctness.

Harold

On Wed, Jun 30, 2010 at 3:13 PM, Harold Lee <harold at hotelling.net> wrote:
> If none of the filenames contain spaces(!), you can write a regexp to
> match the end of the line using the $ anchor, e.g.
>
> perl -p -e '/([^ ]+)$/; print "rm -f $1\n";' < files-to-delete.txt
>
> Harold
>
> On Wed, Jun 30, 2010 at 3:01 PM, David Spencer, Internet Handyman
> <spencer at pageweavers.com> wrote:
>> Guys, I'm sorry about asking this on the list; but I seem to have a mental
>> block when it comes to regular expressions. Here's what I'm trying to do:
>>
>> I have a lot of directories with a vast number of files, some of which I wish
>> to delete based on the month they were created. I've built a file from some
>> full directory listings that has all the files I wish to delete. (Just go with
>> me on this and don't suggest alternative methods of performing the task - I'm
>> simplfying the job so it can be explained more easily.)
>>
>> A snippet of the file would look like this:
>>
>> -rw-------  1 auser auser 3.7K Apr 12 10:11 auser/folder/new/127109228.file
>> -rw-------  1 auser auser  16K Apr 12 12:32 auser/folder/new/127110076.file
>>
>> I would like to write either single-line perl command or a nano search and
>> replace to substitute the directory info and replace it with a file delete
>> so it would look like this:
>>
>> rm -f auser/folder/new/127109228.file
>> rm -f auser/folder/new/127110076.file
>>
>> Then I can just execute converted directory file as a shell script and
>> delete my files. But I'm having a brain-freeze on what a valid regex would
>> look like to match. Help??
>>
>> Thanks again,
>>
>>
>> -- Dave Spencer, PageWeavers
>> _______________________________________________
>> vox-tech mailing list
>> vox-tech at lists.lugod.org
>> http://lists.lugod.org/mailman/listinfo/vox-tech
>>
>


More information about the vox-tech mailing list