batch to delete end of line

Lenovo / C200
May 17, 2009 at 02:14:16
Specs: Windows XP Pro SP3
How can I delete all text in every single line in txt file after specific sign in line.

For example, if I have:
eeeeeeeeee \: marko
bbbbbbbbbbbbb \: juuure
vvvvvvvvvvvvvvvvvvvv \: sanader

I want to delete all text after "\:", and my new.txt has to looks like:

eeeeeeeeee \:
bbbbbbbbbbbbb \:
vvvvvvvvvvvvvvvvvvvv \:

Can someon help me?


See More: batch to delete end of line

Report •


#1
May 17, 2009 at 04:17:23
@echo off > newfile & setLocal EnableDelayedExpansion

for /f "tokens=1-2 delims= " %%a in (myfile) do (
echo %%a %%b >> newfile
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
May 17, 2009 at 04:34:23
The response was very quickly and successful!

Thank you very much.


Report •

#3
August 3, 2009 at 09:20:32
Is it possible to achieve this same effect, but delete the contents of the line prior to the "\:" symbol. So for example, after running the batch on the text file mentioned in the first post, we'd have:

marko
jure
sanader


Report •

Related Solutions

#4
August 3, 2009 at 16:19:33
Also of note - it seems the batch file above uses just "\" as the delim, as opposed to "\:". Is it possible to use the entire string \: as the delim?

Report •

#5
August 3, 2009 at 17:02:51
this is easily done with vbscript too


Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
	strLine = objFile.ReadLine	
	s = Split(strLine,"\:")	
	WScript.Echo s(UBound(s))
Loop
objFile.Close

GNU win32 packages | Gawk


Report •

#6
August 3, 2009 at 22:48:51
@echo off > newfile & setLocal EnableDelayedExpansion

for /f "tokens=3 delims= " %%a in (myfile) do (
echo %%a >> newfile
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#7
August 4, 2009 at 01:48:17
Thank you so much everyone for your answers.

Report •


Ask Question