Page 1 of 1

change the sequence numbers contained in a line

Posted: Sat Feb 18, 2012 9:40 am
by CrisCia
A file contains lines with numbers. These numbers are used in other files.
I want to change the numbering.

File A:..................File B:..................File C:
DG_111_aaa........DG_111_aaa........DG_112_bbb
DG_112_bbb
DG_113_bbb


New numbers:

File A:..................File B:.................File C:
DG_101_aaa........DG_101_aaa........DG_102_bbb
DG_102_bbb
DG_103_bbb

Posted: Sat Feb 18, 2012 2:47 pm
by ben_josephs
Search for: DG_([0-9])1([0-9])_

[X] Regular expression

Replace with: DG_${1}0${2}_

[ ] Literal replacement [i.e., not selected]

Options

Regular expression syntax
[X] Perl/ECMAScript
OR
[X] POSIX Extended

Replacement format syntax
[X] Perl
OR
[X] Extended

Posted: Mon Feb 20, 2012 8:28 am
by CrisCia
in this example, I have to do the research for 3 times.

May I replace everything with one command?

Posted: Mon Feb 20, 2012 9:04 am
by ben_josephs
What three items?

Posted: Mon Feb 20, 2012 9:13 am
by CrisCia
I am sorry, was an incomplete example

File A:..................File B:..................File C:
DG_109_aaa........DG_109_aaa........DG_109_bbb
DG_110_bbb........DG_110_aaa........DG_110_bbb
DG_111_bbb........DG_111_aaa........DG_111_bbb

New numbers:

File A:..................File B:.................File C:
DG_119_aaa........DG_119_aaa........DG_119_bbb
DG_120_bbb........DG_120_aaa........DG_120_bbb
DG_121_bbb........DG_121_aaa........DG_121_bbb

Posted: Mon Feb 20, 2012 10:42 am
by ben_josephs
I'm assuming the middle digits 0, 1 and 2 are to be increased by 1:

Use conditional expressions:
Search for: DG_([0-9])(?:(0)|(1)|(2))([0-9])_

[X] Regular expression
Replace with: DG_${1}(?2(1):?3(2):?4(3))${5}_

[ ] Literal replacement [i.e., not selected]

Options

Regular expression syntax
[X] Perl/ECMAScript

Replacement format syntax
[X] Extended
Search for conditional expression in WildEdit's help and choose Extended Format String Syntax.

This sort of thing is much more simply done with a script.

Posted: Mon Feb 20, 2012 5:21 pm
by CrisCia
last case, if I can...

generally, if I want to increase or decrease the sample numbers of 2 ???

File A:..................File B:..................File C:
DG_108_aaa........DG_108_aaa........DG_108_bbb
DG_109_aaa........DG_109_aaa........DG_109_bbb
DG_110_bbb........DG_110_aaa........DG_110_bbb
DG_111_bbb........DG_111_aaa........DG_111_bbb

Increase of 2

New numbers:

File A:..................File B:.................File C:
DG_110_aaa........DG_110_aaa........DG_110_bbb
DG_111_bbb........DG_111_aaa........DG_111_bbb
DG_112_bbb........DG_112_aaa........DG_112_bbb
DG_113_bbb........DG_113_aaa........DG_113_bbb

Posted: Mon Feb 20, 2012 6:00 pm
by ben_josephs
WildEdit only performs textual manipulation; it can't do arithmetic. So within WildEdit you can only do what you need by a tedious extension of the method I showed you.

Or you can do it with a script.