Solved How to write a bat program to remove the prefix two bytes

November 16, 2015 at 22:48:07
Specs: Windows 7
I have a csv file as below: (first line is the field name)

---------------------------
__name,ID,card-no
^^wxyz,A1234567890,5555444433332222
$ ABCD,A2345678901,5555333344441111
$ zzzz,D1345678901,5555111122223333
# sssssss,A1341678931,5555999922223333
^^wwww,A1267109732,4444111188880000
$ uuuuuuu,B1327630912,3333111166662222
--------------------------

I want to remove the prefix two bytes at each line, the output result as below:

-----------------------------
name,ID,card-no
wxyz,A1234567890,5555444433332222
ABCD,A2345678901,5555333344441111
zzzz,D1345678901,5555111122223333
sssssss,A1341678931,5555999922223333
wwww,A1267109732,4444111188880000
uuuuuuu,B1327630912,3333111166662222
-------------------------------


the prefix two bytes will be any code(including spaces). how to write th bat program

message edited by wangw627


See More: How to write a bat program to remove the prefix two bytes

Report •


#1
November 17, 2015 at 01:51:59
✔ Best Answer
@Echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%A in (csvfile.csv) do (
       set line=%%A
       set line=!line:~2!
       echo !line!>>newcsv.csv
)
pause

Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.


Report •

#2
November 17, 2015 at 02:05:05
::====== script starts here ===============
::
:: wangw.bat 2015-11-17 16:54:15.36
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

:main
for /f "tokens=* delims= " %%a in (myfile) do (
set S=%%a
set S=!S:~2!
echo.!S!
) >> NEWFILE
goto :eof
::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Report •
Related Solutions


Ask Question