views:

44

answers:

2

Hi,

i want to nest for loop inside batch to delete Carriage return. I did liek this but not working please help

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (Listfile.txt) do (
set /a N+=1
set v!N!=%%a
)

for /l %%i in (1, 1, %N%) do (
echo !v%%i!
for /r "tokens=* delims=" %%i in (windows.cpp) do (  
echo %%i >> Linux11.cpp
)
pause

Here i want to check with windows.cpp. if its working i like to change windows .cpp with !v%%i!. Please help on this

A: 

It would be probably easiest to use some unix2dos/dos2unix converter to do that or some win32 flavor of sed.

RC
+1  A: 

You cannot do this in a batch file. You have no way of addressing or writing arbitrary characters. Every tool on Windows normally makes sure to output Windows line breaks (i.e. CR+LF). Some can read Unix-style line breaks just fine, which is why you can easily convert from them. But to them isn't possible.

Also as a word of caution: Source code files often contain blank lines (at least mine do) that are for readability. for /f skips empty lines which is why you're mangling the files for your human readers there. Please don't do that.

As for your question: When nesting two loops you have to make sure that they don't use the same loop variable. Show me a language where code like you wrote actually works.

Something like

for /l %%i in (1, 1, %N%) do ( 
  echo !v%%i! 
  for /r "tokens=* delims=" %%l in ("!v%%i!") do (   
    rem do whatever you want to do with the lines      )
)

should probably work better (you missed the final closing parenthesis as well). Thing to remember: If you want to use a certain variable instead of a fixed file name it surely helps replacing that fixed file name by that variable.

Joey
here in echo %%i >> Linux11.cpp i am getting the file name , its not copying the content in that *.cpp files in Listfile.txt
echo just writes a string to the screen ... what makes you think that it would actually do anything with a file's contents?
Joey