Hello, i need to remove the first 8 characters, as well as the last 20 characters of each line in a text file, regardless of what the characters are.
I'm fine with using JREPL or some other utility like that to accomplish this.
Remove characters from text file
Moderator: DosItHelp
-
- Posts: 3
- Joined: 23 Oct 2018 08:18
Re: Remove characters from text file
I solved my own problem, here is the code:
Code: Select all
for /f "tokens=*" %%D in (example.txt) do (
set texte=%%D
set texte=!texte:~8!
set texte=!texte:~0,-19!
echo "!texte: = !" >> temp.txt
)
type temp.txt > example.txt
del temp.txt
Re: Remove characters from text file
Your task should still work with pure Batch as long as the line lengths don't exceed 1021 characters.
Steffen
Code: Select all
@echo off &setlocal
set "txt=test.txt"
setlocal EnableDelayedExpansion
<"!txt!" >"!txt!.~tmp" (
for /f %%i in ('type "!txt!"^|find /c /v ""') do for /l %%j in (1 1 %%i) do (
set "ln=" &set /p "ln="
if not defined ln (
echo(
) else (
echo(!ln:~8,-20!
)
)
)
move /y "!txt!.~tmp" "!txt!"
endlocal
Re: Remove characters from text file
big_caballito wrote: ↑04 Dec 2018 12:26I solved my own problem, here is the code:Code: Select all
for /f "tokens=*" %%D in (example.txt) do ( set texte=%%D set texte=!texte:~8! set texte=!texte:~0,-19! echo "!texte: = !" >> temp.txt ) type temp.txt > example.txt del temp.txt
Code: Select all
for /F delims^=^ eol^= %%r in (example.txt) do (
set "texte=%%r"
set "texte=!texte:~8,-19!"
>>temp.txt (echo("!texte: = !")
)
type temp.txt > example.txt
del temp.txt
several topics on all of the above.
-
- Posts: 3
- Joined: 23 Oct 2018 08:18
Re: Remove characters from text file
Thanks, you two