extracting data from .txt file

Microsoft Windows xp professional w/serv...
March 24, 2010 at 17:15:27
Specs: Windows XP
Hi guys, I need your help! I want to extract
some numerical values at the end of a batch of
text files. The data looks like this.

118,[b]2084400000[/b].
192,[b]562788000[/b].
226,[b]2084400000[/b].
1826,[b]681124002.440932[/b]
1877,[b]1612346469.56606[/b]
1913,[b]94725834.3182483[/b]
1934,[b]256142956.993768[/b]
1960,[b]530178195.204839[/b]
1981,[b]1926830586.69152[/b]

I need to extract the bolded numbers after the
first number and comma to an excel (or rather
openoffice calc) file for further editing. It is far
too tedious and time consuming to do it by
hand for the 168 similar files so if you can tell
me how to do this in batches, it would be
much appreciated!


See More: extracting data from .txt file

Report •


#1
March 24, 2010 at 18:47:35
get awk/sed from GNU win32

awk -F"," '{print $2}' file

sed 's/^.*,//' file

GNU win32 packages | Gawk


Report •

#2
March 24, 2010 at 21:19:36
I guess you intended [b][/b] to show bold but it didn't work.

Try this:

-----------------------
@echo off > newfile & setLocal enableDELAYedeXpansion

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


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

M2


Report •

#3
March 25, 2010 at 04:25:24
Sorry for coming off as a complete noob...but what am I
supposed to do with these? I have no idea.

@Mechanix
How should I use your script? Just copy it in a txt file, rename
it to bat and run it?

@ghostdog
I downloaded those but I don't know what to make of them.
How should I run the script? Txt file to bat?

(Also, there was no awk, only Awka, they are the same,
right?)


Report •

Related Solutions

#4
March 25, 2010 at 05:08:17
I have uploaded one of the files here:
http://www.mediafire.com/file/mydnnmqgxyj/blinds_me_dimming_0deg.txt

Imagive 168 files like this and that I am interested in the values in the
last 9 lines.


Report •

#5
March 25, 2010 at 06:13:00
@bohemian, its gawk, not awk. Also, you can download coreutils also, which contains many unix tools essential to supplement batch programming.

Also, gawk.exe and sed.exe are just executables. much like ping.exe, ftp.exe etc... so just use it on the command line , or inside batch script as normal.

on the command line:

c:\test> sed "s/^.*,//" file 

in the batch file

@echo off
sed "s/^.*,//" file

to get last 9 lines of the line, use tail command (after you install coreutils)

c:\test> tail -9 blinds_me_dimming_0deg.txt |  sed "s/^.*,//"
2084400000.0
562788000.0
2084400000.0
646024411.608784
1806849219.6864
94569712.5783913
275009253.911838
589030446.63428
1956904501.68398


that's all you need.

GNU win32 packages | Gawk


Report •

#6
March 25, 2010 at 07:25:52
We're all noobs sooner or later.

Paste the script below, between the =====, into notepad. Make a new directory:

C:\mystuff

Save the script to:

c:\mystuff\my.txt

Then REN my.txt my.bat

Now put the file you posted the link to in c:\mystuff and:

REN blinds_me_dimming_0deg.txt mydata

NOW type my and press enter.

The result will be in newfile.

=======================================
@echo off > newfile & setLocal enableDELAYedeXpansion

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

set /a N-=9

for /f "skip=%N% tokens=1-2 delims=," %%a in (mydata) do (
>> newfile echo.%%b
)


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

M2


Report •

Ask Question