#1 2010-09-16 00:22

pehrlabel
Member
Registered: 2010-09-15
Posts: 2

Swap characters by position?

hello i have these files sorted by month and then year, and they don't sort nicely in the computer by date (because month is first, instead of year). can anyone help me swap these, add an underscore, and add add a "20" to the front all in one go?

0310_us.txt => 2010_03_us.txt

another example

1109_au.txt => 2009_11_au.txt

see it has the month as the first two characters, and the year by the third and fourth character.

thanks! adam

Offline

#2 2010-09-16 06:56

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Swap characters by position?

Hi adam, welcome! smile

FROM:
0310_us.txt
1109_au.txt

TO:
2010_03_us.txt
2009_11_au.txt

USE an RegEx-Rule as follows:

RegEx:
expression "(\d\d)(\d\d)"
Replace with "20$2_$1"
(skip extension)


Explanation:
\d ==> is an RegEx to match one single digit
\d\d => will match two digits
(...) => will group what is matched for later reuse by "$1"
Ahh, and don't use that ""-quotes in real, they are only to clarify.

So we have two backreference groups we can reference to by using "$1" and "$2"
In the replacement we exchange this two groups from $1 $2 to $2 $1 and add literal text as "20" and "_"
The rest of the string is added by ReNamer automatically.


See the WIKI for more about this:
=> http://www.den4b.com/wiki/ReNamer:Rules for more about using Rules and
=> http://www.den4b.com/wiki/ReNamer:Regular_Expressions for more about the RegEx Syntax.

HTH?  big_smile
If yes spread the word about ReNamer ... and help two others too and/or read my sig big_smile

Last edited by Stefan (2010-09-16 06:59)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2010-09-17 07:29

pehrlabel
Member
Registered: 2010-09-15
Posts: 2

Re: Swap characters by position?

Thank you so so so much. I love it. It worked instantly. I Linked-In about ReNamer just now.

Offline

Board footer

Powered by FluxBB