How to remove the first and last character from a file using batch script?
- by infant programmer
This is my input file content which I am using to copy to the output file.
#sdfs|dfasf|sdfs|
sdfs|df!@$%%*&!sdffs|
sasdfasfa|dfsdf|#sdfs|
What I need to do is to omit the first character '#' and last character '|' in the output file.
So the output will be,
sdfs|dfasf|sdfs|
sdfs|df!@$%%*&!sdffs|
sasdfasfa|dfsdf|#sdfs
Batch script is new to me, but I tried my best and tried these codes,
:: drop first and last char
@echo off > xyz.txt & setLocal EnableDelayedExpansion
for /f "tokens=* delims=" %%a in (E:\abc1.txt) do (
set str=%%a
set str=!str:~1!
echo !str!>> xyz.txt
)
and
@echo off > xyz.txt
setLocal EnableDelayedExpansion
for /f "tokens=1,2 delims= " %%a in (E:\abc1.txt) do (
set /a N+=1
if !N! gtr 2 ( echo %%a >> xyz.txt
)
else (
set str=%%a
set str=!str:#=!
echo !str! >> xyz.txt
)
)
As you can see they are not able to produce the required output.