save a column of numbers to a text file

May 20, 2010 at 14:31:00
Specs: Windows Vista
Hi,
I would like to save just the numbers in a text file to another text file on each line if this is possible. The original file looks like this
1:a string
3:new string

I would like the new file to look like this
1
3
Removing the:a string


See More: save a column of numbers to a text file

Report •

#1
May 20, 2010 at 15:10:25
if the colon is consistant, this might work:
for /f "tokens=1 delims=:" %%a in (file) do >>newfile echo %%a

Report •

#2
May 20, 2010 at 15:49:23
Hi nbrane,

Thankyou for that it works fine.
I do have another question, now I have a single column of numbers in a new text file is it possible to use these numbers as line numbers to extract the line information from another text file.


Report •

#3
May 20, 2010 at 19:05:08
line numbers, or line contents? what i mean is f/e you have 3:
get line#3 from the other file? or do you mean look in the other file for
the string "3", (or a line beginning with "3" or "3:")
either one is feasible.

Report •

Related Solutions

#4
May 21, 2010 at 08:32:03
Hi nbrane,

Now I have a second file with the numbers 1 and 3. I would like to retrieve the contents of another text file that has information on lines 1 and 3 and place the new contents in a new file.


Report •

#5
May 21, 2010 at 17:26:02
there are lots of ways to accomplish this, but most of them are slow. This seems to be the quickest, if you don't run out of "string space" (the size of zz):
@echo off & setlocal enabledelayedexpansion
set zz=_
for /f %%a in (numbers) do set zz=!zz!%%a_
for /f "tokens=1* delims=[]" %%a in ('find /n /v ""^<fil') do (
set test=!zz:_%%a_=!
if !test! neq !zz! echo %%b
)
::----- end - edited fixed logic error

Report •

#6
May 22, 2010 at 07:55:56
Thanks nbrane,

That worked fine using cmd what do I need to change the output to go to a text file? I seem to be going around in circles


Report •

#7
May 22, 2010 at 10:35:57
... (script down to here as written)
if !test! neq !zz! >>newfile echo %%b

Report •

#8
May 22, 2010 at 18:01:15
Hi nbrane,

That's great it works I now have 3 text files so I can see what is happening and will help with another post I have. Please see what I have so far it may need inproving

@echo off & setLocal enableDELAYedexpansion
IF exist Fil1.txt del Fil1.txt
IF exist numbers.txt del numbers.txt
IF exist Fil2.txt del Fil2.txt
FINDSTR /N green/yellow grnyel.txt>>Fil1.txt
FINDSTR /N END grnyel.txt>>Fil1.txt
for /f "tokens=1 delims=:" %%a in (Fil1.txt) do >>numbers.txt echo %%a
@echo off & setlocal enabledelayedexpansion
set zz=_
for /f %%a in (numbers.txt) do set zz=!zz!%%a_
for /f "tokens=1* delims=[]" %%a in ('find /n /v ""^<Fil2.txt') do (
set test=!zz:_%%a_=!
if !test! neq !zz! >>newfile.txt echo %%b
)


Report •

Ask Question