removing the 'enter' character from text file

January 6, 2010 at 04:15:02
Specs: Windows XP
i've a.txt with data

abc,(space)
def,(space)
ghi,(space)

i need batch code to produce output like

abc,def

that is omit 'space' and 'enter' at all line ends,
omit last line entirely ,
omit previous line's comma too

plz help ....


See More: removing the enter character from text file

Report •

#1
January 6, 2010 at 04:44:12
@echo off > newfile & setLocal enableDELAYedeXpansion

set /a N=-1

for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
)
set L=0

for /f "tokens=1 delims= " %%a in (myfile) do (
set /a L+=1
if !L! gtr !N! goto :done
set S=!S!%%a
)
:done
set S=!S:~0,-1!
> newfile echo.!S!


=====================================
Helping others achieve escape felicity

M2


Report •

#2
January 6, 2010 at 04:58:58
sorryy...to say

its givin only partial o/p


Report •

#3
January 6, 2010 at 05:25:28
What is partial o/p?


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
January 6, 2010 at 08:43:56
@M2: Why did you use tokens=1? If the input file has any lines with spaces embedded in the text, only the first word of the line will be output. You need to remove the space(s) only if they are at the end of the line. (P.S. Happy New Year!)

Report •

#5
January 6, 2010 at 09:14:37
Hi klint,

Happy New Year!

Because there were no spaces other than the trailing ones.

==================================
While I've got you on the horn...

Why doesn't this lose the \?

===========================
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims=\" %%a in ("!CD!") do (
echo %%a
)


=====================================
Helping others achieve escape felicity

M2


Report •

#6
January 6, 2010 at 09:57:30
It doesn't lose the \ because when you use tokens=* it includes
the whole string. It only tokenizes when you specify tokens=1-5
or similar.

Report •

#7
January 6, 2010 at 09:59:14
While I'm thinking about it, removing trailing spaces is such a
common thing I'm surprised cmd.exe doesn't give you a neat
way of doing it.

Report •

#8
January 6, 2010 at 19:13:08
suppose my input file is

this is line 1,
this is line 2,
this is line 3,

my required output is

this is line 1,this is line 2,this is line 3

that is all in one line and comma of last line removed


Report •

#9
January 6, 2010 at 21:04:28
hi all

i made some changes...it finally got worked...thanks to you all.....

thnx a lot


Report •

Ask Question