small programming question

Toralf Lund toralf at procaptura.com
Mon May 23 13:27:58 UTC 2005


Toralf Lund wrote:

> Claude Jones wrote:
>
>> Could someone help. I have chosen a bad naming convention for a long 
>> list, and I need to make a small alteration. The list looks like the 
>> following
>> 001-Fig 1-1.jpg   013-Fig 4-4a.jpg  024-Fig 5-6.jpg   035-Fig 5-17.jpg
>> etc...
>> I would like to add a 0 to each group of three numbers at the 
>> beginning of each name so that 001-Fig 1-1.jpg becomes 0010-Fig 
>> 1--1.jpg for example.
>> Could someone help me with the quick way to do this?  
>>
> How about
>
> perl -pi~ -e 's/^[0-9]/0$&/' yourfile
>
> ?
>
> (Replaces a digit at the start of a line with 0 followed by the 
> orignal digit. Backup file in yourfile~)

I notice now that this was not quite what you wanted, though.

perl -pi~ -e 's/^[0-9]{3}/$&0/' yourfile

or

perl -pi~ -e 's/-F/0$&/' yourfile

is probably more correct.

- T




More information about the fedora-list mailing list