abc.txt contains
sachin
ramesh
suresh
ramesh
ganguly
i want to append a string lets say "xyz" for every occurance of "ramesh" in the above file.
output shud be :
sachin
xyz
ramesh
suresh
xyz
ramesh
ganguly
thanx in advance ..reply awaited.
Re: Code for how to append a string for every occurance.
Moderator: DosItHelp
Re: Code for how to append a string for every occurance.
'
Assuming case insensitive match.
Assuming case insensitive match.
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$inFile=abc.txt"
set "$ouFile=out.txt"
type "!$inFile!"
> "!$ouFile!" (
for /f "usebackq delims=" %%? in (
"!$inFile!"
) do set "$=%%?" &if /i "!$:ramesh=!" == "%%?" (
(echo.%%?)
) else (echo.xyz) &(echo.%%?)
)
type "!$ouFile!"
pause
endlocal &exit /b 0
Re: Code for how to append a string for every occurance.
Hello dyreen,
The above code is working fine but the result is not geting copied to out file.
Thanx a ton..
The above code is working fine but the result is not geting copied to out file.
Thanx a ton..
Re: Code for how to append a string for every occurance.
Another option: GnuSED for Windows produces the result you need
Code: Select all
@echo off
sed "s/^ramesh$/xyz\n&/" abc.txt >out.txt