replace 250th charcter

September 14, 2010 at 13:38:20
Specs: Windows XP
dear Friends:
I need a batch program to replace a 250th char on all rows in a text file with million records. Could you please throw a sample code?

Thanks


See More: replace 250th charcter

Report •

#1
September 14, 2010 at 19:31:41
download gawk for windows

c:\test> gawk.exe "{print substr($0,1,249)\"X\"substr($0,251)}" file > t
c:\test> ren t file

GNU win32 packages | Gawk


Report •

#2
September 15, 2010 at 02:29:45
If the new char is X:

=======================================
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (bigfile) do (
set S=%%a
set pre=!S:~0,249!
set post=!S:~250!
>> newfile echo.!pre!X!post!
)


=====================================
Helping others achieve escape felicity

M2


Report •

#3
September 15, 2010 at 08:44:51
@M2, i think it should be
set post=!S:~250!

GNU win32 packages | Gawk


Report •

Related Solutions

#4
September 16, 2010 at 05:35:13
ghostdog,

Thanks for catching my mistake.


=====================================
Helping others achieve escape felicity

M2


Report •

#5
September 16, 2010 at 07:46:55
Hi M2 & Ghostdog
Thank you very much for your responses. It is working like a champ but I think I am replacing the 250th character so why are you saying that set post=!S:~250!
instead of set post=!S:~251!

Regards


Report •

#6
September 16, 2010 at 08:42:38
post=!S:~250! skips 250 and takes 'the rest', which is what's needed.

pre os the first 249.

Then your new char 250.

Then the post.


=====================================
Helping others achieve escape felicity

M2


Report •

Ask Question