Replace all instances of a character at a specific location

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
adame
Posts: 1
Joined: Fri Aug 18, 2006 6:23 pm

Replace all instances of a character at a specific location

Post by adame »

I need to replace all instances of a character at a specific location on a line of text. For instance, I need to replace all instances of the 106th character in the line below with the same chacter followed by a newline (\n). I have tried recording a macro and copy/pasting into the search function, but the macro seems to remember the search terms, not replace them each time the macro runs.

Here's the line of text, in this case, I need to replace all instances of "\" but this could be any character, such as "~" or "+", etc.

ISA*00* *00* *ZZ*123456789012345*ZZ*098765432154321*060502*0830*U*00300*000001512*0*P*~\GS*PO*1234567489012345*098765432154321*060502*0830*1*X*003030\ST*850*0001\BEG*00*SA*22789149285**060502\DTM*002*060503\N9*ZZ*00\MSG*\N1*BY**91*49546MGR\N1*ST**91*49546MGR\N3*5700 28th St. SE\N4*Lincoln*NE*49546*USA\N1*BT**91*49546MGR\N3*5700 28th St. SE\N4*Lincoln*NE*49546*USA\PO1*1*3*CA*66.37**VN*00682*IN*00682*PD*Dixie Cups\PO4***CA\CTT*1*3\SE*16*0001\ST*850*0002\BEG*00*SA*22789416160**060502\DTM*002*060503\N9*ZZ*00\MSG*\N1*BY**91*48341CYM\N1*ST**91*48341CYM\N3*1234 5th ST\N4*Omaha*NE*48341*USA\N1*BT**91*48341CYM\N3*`123 4th St\N4*Omaha*NE*48341*USA\PO1*1*1*CA*26.99**VN*PC1234*IN*PC1234*PD*Cleaning Product\PO4***CA\PO1*2*1*CA*107.99**VN*134ZA*IN*134ZA*PD*Cloth Dust\PO4***CA\CTT*2*2\SE*18*0002\GE*2*1\IEA*1*000001512\
User avatar
Niels H. Veldhuijzen
Posts: 15
Joined: Mon Apr 19, 2004 12:12 pm
Location: Zutphen, The Netherlands
Contact:

Post by Niels H. Veldhuijzen »

Dear Adame,

Try this (no POSIX):

Change

(\.\{105\}\)(\.\)

into

\1\n\2

RE on.

I guarantee nothing, but it seemed to have worked with me. Maybe I left out one or two parentheses; but something like this should do the trick.
Yours sincerely,

Niels H. Veldhuijzen
Zutphen, The Netherlands
ben_josephs
Posts: 2459
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

That puts a newline before the 106th character. The original poster seems to be asking how to insert a newline after the 106th character. That can be done simply like this:
Find what: ^.{106}
Replace with: \0\n

[X] Regular expression
or
Find what: ^(.{106})
Replace with: \1\n

[X] Regular expression
These assume you are using Posix regular expression syntax, which makes for rather more readable regexes:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Post Reply