-1

Kindly help with a windows batch script that will remove the leading zeroes in a text file and write to a new file without the zeroes.

Input file format

0265952076
0263097520
0578361217
0266127789
0505834686
0578361190

Output format

265952076
263097520
578361217
266127789
505834686
578361190

Thank you.

djikay
  • 10,450
  • 8
  • 41
  • 52
  • i tried with script but am only able to write the last on the file onto the new file. @ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION ::Extract only the first 5 characters FOR /f "delims=" %%a IN (%1) DO ( SET "var1=%%a" ) ECHO %var1:~1,9%>max_test.txt – user3798582 Jul 02 '14 at 19:29
  • put the last `)` to the very end (after max_test.txt) to include the echo into the loop. – Stephan Jul 02 '14 at 19:43

2 Answers2

1
@echo off
(for /f "tokens=* delims=0" %%a in (inputFile) do echo(%%a)>outputFile

This uses the hability of for /f to split a string in tokens, removing the delimiters used for the splitting. As the 0 is used as delimiter, but we are asking for all the string in only one token, for will discard initial delimiters until the first token is found, resulting in leading zeroes removed.

MC ND
  • 69,615
  • 8
  • 84
  • 126
0

This uses a helper batch file called repl.bat (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place repl.bat in the same folder as the batch file or in a folder that is on the path.

@echo off
type file.txt | repl "^0*" "" >newfile.txt 
pause
foxidrive
  • 40,353
  • 10
  • 53
  • 68