Truncate the line

April 22, 2010 at 11:35:30
Specs: Windows XP
Hi all,

I am trying to truncate the line and write it to the other file

Here is my req

input.txt
-------------
RelativePath="..\ExCommon\AbstractEditablePropsContex
t.cpp"
RelativePath="..\ExCommon\AFPDrawPart.cpp"
RelativePath="..\Campaigner\AfpdsSourceFile.cpp"
RelativePath="..\Campaigner\AFPFont.cpp"
RelativePath="..\ExCommon\AFPGlobal.cpp"
RelativePath="..\Campaigner\Application.cpp"
RelativePath="..\Campaigner\AppQHH.cpp"
RelativePath="..\Campaigner\AppQueue.cpp"

output.txt
--------------
ExCommon\AbstractEditablePropsContext.cpp
ExCommon\AFPDrawPart.cpp
Campaigner\AfpdsSourceFile.cpp
Campaigner\AFPFont.cpp
ExCommon\AFPGlobal.cpp
Campaigner\Application.cpp
Campaigner\AppQHH.cpp
Campaigner\AppQueue.cpp

here is the script i wrote.

FOR /F "tokens=1 delims= " %%A IN ('TYPE
"C:\input.txt"') DO ^
set name="%%A" ^
set newname=%name:~17,-1% ^
echo %newname% > C:\output.txt

it is not generating the output.text can you please correct
the script if i am doing wrong.

Thanks.


See More: Truncate the line

Report •

#1
April 22, 2010 at 13:03:45
the only thing i see that i don't understand is the ^:
"C:\input.txt"') DO ^
etc.
oh, almost forgot, you'll need enabled use !
not %s
oops, caught another one! remove the quotes around %%a line two:
should be like:
setlocal enabledelayedexpansion
FOR /F "tokens=1 delims= " %%A IN ('TYPE "C:\input.txt"') DO (
set name=%%A
set newname=!name:~17,-1!
>> c:\output.txt echo !newname!
)
::------ end
i think. your echo will put a space at the end of each line i believe, so i switched it around and you need double >>, not > or you will only get one (the last) line.
other than that, it will work, but you don't really need TYPE,
and i would use "tokens=*" just to be safe in case of spaces:
for /f "tokens=*" %%a in (c:\input.txt) do (


Report •

#2
April 22, 2010 at 13:11:58
@echo off & setlocal EnableDelayedExpansion
type nul > "C:\output.txt"
for /F "tokens=1* delims=\" %%a in ('type "C:\input.txt"') do (
  set name=%%b
  set name=!name:~0,-1!
  echo.!name!>> "C:\output.txt"
)


Report •

#3
April 23, 2010 at 09:33:29
Hi nbrane and IVO

thanks for the help , that worked.


thanks.


Report •
Related Solutions


Ask Question