0

I have a first.properties file and I am reading that file, skipping the first 5 lines and creating a new file with the remaining lines of first.properties. This is working fine. But I am getting spaces for each line in the newly created file. I want to remove these spaces.

I have used the following piece of code:

@echo off
set new=0
setlocal ENABLEDELAYEDEXPANSION
for /F "skip=5" %%L in (first.properties) do (
echo %%L>>NewProjectsInfo.properties 
)
endlocal
pause 

first.properties is as follows:

name=abcd
number=bcde
address=cdef
mobile=efgh
worklocation=ghij

Please help me out to remove the spaces.

zb226
  • 9,586
  • 6
  • 49
  • 79
ktraos
  • 127
  • 3
  • 8
  • Do I understand correctly that the entries in `first.properties` (after line 6) have leading and/or trailing spaces? Because the lines you posted (only 5) have not. I'd be surprised if the code you have got mysteriously creates any spaces. – zb226 May 15 '13 at 12:23
  • This is somewhat backwards compared to your question in that it adds characters, but may help: http://stackoverflow.com/questions/10021464/batch-file-to-add-characters-to-beginning-and-end-of-each-line-in-txt-file – Dave May 15 '13 at 12:28

3 Answers3

2

Try this. There can be issues when numbers directly precede the >> characters. You are not using ENABLEDELAYEDEXPANSION so I removed it too.

@echo off
set new=0
setlocal
for /F "skip=5 delims=" %%L in (first.properties) do (
>>NewProjectsInfo.properties echo %%L
)
endlocal
pause 
foxidrive
  • 40,353
  • 10
  • 53
  • 68
1

There is a space after NewProjectsInfo.properties in your code. if that is removed, it works as you expect.

It's sad, but looks like, batch interprets command as entire line & separates out the redirection part. In bash, for example, the command terminates at > symbol itself.

e.g. echo hello >somefile.txt world will put hello world in somefile.txt.

anishsane
  • 20,270
  • 5
  • 40
  • 73
0
@ECHO OFF
SETLOCAL
(
FOR /f "skip=5 delims=" %%i IN (rltsf.txt) DO CALL :unpad %%i
)>output.txt

FC rltsf.txt output.txt
GOTO :eof

:unpad
ECHO %*
GOTO :eof

This approach seemst to work, but I fancy it may be a little sensitive to line-content. Easier to test if we have representative data...

Magoo
  • 77,302
  • 8
  • 62
  • 84