Extract all text from = to end-of-line and concatenate all

August 28, 2012 at 14:47:17
Specs: Windows 7
I have a many files, abc-1.txt to abc-128.txt with text and measurement values (1000 pcs in each).
1. I want to extract just the measurement values (after "="-char) for each of the 127-files
2. Put the result from the 127-files into one concatenated file.
3. Remove all spaces and file names that piping creates.

Below works a little, but I get a lot of text data from each line that I don't want.

(for %f in (abc-*.sav) do type %f >> abc_all.txt) > concatenated_order.txt

Below command removes the lines without the equal sign, but I don't know how to make it a loop for 128-files integrated with above for-statement.

find “=“ abc-1.sav > abc-1.txt

Please help!

Thank you!

See More: Extract all text from = to end-of-line and concatenate all

Report •

August 28, 2012 at 19:22:52
maybe this will work, haven't seen what these files content looks like. might help to post some, otherwise we'll probably keep hitting snags...
@echo off & setlocal
for /L %%i in (1 1 128) do (
for /f "tokens=2 delims==" %%a in (abc-%%i) do if "%%a%" neq "" > newfile echo %%a

Report •

August 29, 2012 at 10:04:03
Thank you for your suggestion. :)
I tried it and got the result: "%%i was unexpected at this time."
Each of the 128 files content looks like below, and there is 1000 of values in each of the 128 files.

local l_fileTable1
l_fileTable1 = {}
l_fileTable1[1] =-516807
l_fileTable1[2] =-516582
l_fileTable1[3] =-515704
l_fileTable1[4] =-514383
l_fileTable1[5] =-514315
l_fileTable1[6] =-515365
l_fileTable1[7] =-515359
l_fileTable1[8] =-514879
l_fileTable1[9] =-515386
l_fileTable1[10] =-514923
l_fileTable1[11] =-514934

Report •

August 29, 2012 at 10:10:53
FYI: Below two variants with small changes to match the extension of the file names didn't make a difference.

for /L %%i in (1 1 128) do (
for /f "tokens=2 delims==" %%a in (abc-%%i.txt) do if "%%a%" neq "" > newfile echo %%a

for /L %%i in (1 1 128) do (
for /f "tokens=2 delims==" %%a in (abc-%%i.sav) do if "%%a%" neq "" > newfile echo %%a

Report •

Related Solutions

August 29, 2012 at 19:39:08
Well, I did mess up the output, should have had double pipe, and I typo-ed an extra percent after the "a" variable, line should look like this:

for /f "tokens=2 delims==" %%a in (abc-%%i) do if "%%a" neq "" >> newfile echo %%a

but aside from that, (dumb mistake on my part), the script ran fine on my xp work-bench. I used no extensions on the input files names, and made only about 4 lines per file (two files), some with "=" and some with none. I doubt it is a "seven" issue.
that still did not generate the same error you got, on my workbench, but you might try the script with these fixes.
That's about all I can contribute, at this point. sorry it failed, and good luck.

Report •

August 30, 2012 at 10:25:36
Thanks you for your help so far.
It persistently complains about the first %%a in:
for /f "tokens=2 delims==" %%a in (abc-%%i) do if "%%a" neq "" >> newfile echo %%a

If I remove the first "%%a" or change it to something else it says that it can't find "abc-%%i" file instead.
By the way, what does "tokens=2 delims==" means?

Yes, I agree it's not a WIn7 vs WinXP issue. For this kind of basic commands the MS-DOS version would not matter, right?

Report •

August 30, 2012 at 14:32:15
It means "get only the second item on each line, as delimited by the equals sign".
I ran another test, using your data, and still no error. i did get the curlys "{}" due to the second line, but that should not affect, i don't think, nor the square brackets, i don't think. I got all the correct output into file "new". but you might just see if the [] are causing a problem on your system by changing them. Or just make a small test set of "dummy" files with a few simple lines, some having the = but make them simple, like test=123
line two
line three = 88
and try the script. also maybe put the dot in front of the echo:
for /f "tokens=2 delims==" %%a in (abc-%%i) do if "%%a" neq "" >> newfile echo. %%a

Report •

Ask Question