Don't get caught on the sed picket fence

I had a problem with numbering in a directory and the files were of the general format: "Lecture1T, Lecture2T, ... Lecture10T, Lecture11T..." and so they are ordered 1,10-19,2,20-29 etc.

I solved the conversion with this and that has nothing to do with picket fences, but the path to using that did.

ls | grep "ure[0-9]T" | rename 's/Lecture/Lecture0/ '

The following example shows what I mean.

ls | grep "ure[0-9]T" | sed 's_Lecture_&0_'

The picket fence that shows up in many scripts can be removed by using the underscore _ character as a delimiter and then you don't see things like s/\/bin\/foo\/bar\/baz\/scary/new name/ and the like. It is a lot easier and more understandable as "sed s_/bin/foo/bar/baz/scary_new name_"

I now have this urge to rename them in zero inclusive logic as Lecture00,, Lecture(n-1), but I will fight it and hopefully I will have enough sense to know that it will bite me later when I have a script that goes from 1 to n.

Just a small caveat (=warning), rename is a perl script and it does not operate the same was as sed and as a result will not accept _underscore as the delimiter.

0 comments:

Contributors

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen