Removing or moving parts inconsistent parts of a file name

A swapping-ground for Regular Expression syntax

Removing or moving parts inconsistent parts of a file name

Postby mwbutler » Wed Jul 13, 2016 4:12 pm

I have about 30K files that have been named in the following manner

Spr16_51_5881_ELA_10_XXXXX1234X_SMITH-JOHN.pdf
Spr16_51_0021_MAT_03_XXXXX4321X_JONES-LISA.pdf

The XXX section in the middle may not always end with an X but the section between the two "_" is always 10 characters and will always have 5 leading X's. The string in front of the XXX section is not always the same and may be shorter or longer however, the the XXX section will always start after the 5th "_".

Ultimately what I would like to do is either move the LASTNAME-FIRSTNAME section (which obviously can be any length) to the front of the file like below

SMITH-JOHN_Spr16_51_5881_ELA_10_XXXXX1234X.pdf
JONES-LISA_Spr16_51_0021_MAT_03_XXXXX4321X.pdf

or

Remove the 10 character XXX section all together like below

Spr16_51_5881_ELA_10_SMITH-JOHN.pdf
Spr16_51_0021_MAT_03_JONES-LISA.pdf

Please help!
mwbutler
 
Posts: 2
Joined: Wed Jul 13, 2016 3:54 pm

Re: Removing or moving parts inconsistent parts of a file name

Postby therube » Wed Jul 13, 2016 5:47 pm

If the first number of fields are always the same (fixed) lengths, then:

5:Remove
From: 21 To: 31
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Removing or moving parts inconsistent parts of a file name

Postby mwbutler » Wed Jul 13, 2016 7:23 pm

Thank you for the reply. The X's start at either position 19 or 21
mwbutler
 
Posts: 2
Joined: Wed Jul 13, 2016 3:54 pm

Re: Removing or moving parts inconsistent parts of a file name

Postby therube » Sun Jul 17, 2016 11:58 am

1:RegEx

Code: Select all
Match:  (.*)_(.*)_(.*)_(.*)_(.*)_(.*)_(.*)
Replace:  \1_\2_\3_\4_\5_\7
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm


Return to Regular Expressions