I need to capture line 6 and line 147 of each file, concatenate line 6
and line 147 and output that line to a file.
I would like to end up with a file of 10,000 lines, each line would
have each text file's line 6 and line 147 combined.
thanks
This seemed to work for me ...
@echo off
setlocal
if exist output.txt del output.txt
set source=d:\pathspec\filemask*.ext
:: set source=*.* % for all files in current directory %
attrib +h "%¬f0" % hide this file to avoid processing it %
for %%a in (%source%) do (
find /n /v "" %%a > %temp%\tmp.txt
for /f "tokens=1* delims=]" %%C in (
'find "[6]" ^< %temp%\tmp.txt') do (
set /p=%%D) >> output.txt <nul
for /f "tokens=1* delims=]" %%C in (
'find "[147]" ^< %temp%\tmp.txt') do (
echo.%%D) >> output.txt
set /p=.<nul% optional progress indicator %
)
del %temp%\tmp.txt
attrib -h "%¬f0" % restore %
I have no idea how fast (or low) it might be.
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Thanks Tom, works great - the only problem is that it does not bring
over the entire line.
It seems to bring over about 1100 columns, many lines are over 2500
columns.
This must be a limitation in variable size or what find can handle?
Any thoughts?
thanks again
<snip>
> Thanks Tom, works great - the only problem is that it does not bring over
> the entire line.
>
> It seems to bring over about 1100 columns, many lines are over 2500
> columns.
> This must be a limitation in variable size or what find can handle? Any
> thoughts?
awk "NR==6{X=$0};NR==147{print X $0}" source > target
where awk is any decent Windows port - I prefer gawk.exe (free and open
source) from <http://gnuwin32.sourceforge.net/packages/gawk.htm>
If you want a tab between the two lines, change X $0 to X,$0
If you want a space make that X \" \" $0
otherwise, you get no delimiter at all between the lines.
(gawk handles lines at least 6KB long)
--
T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
It's a command line limitation at 1024 lines.
I guess you need a third party application, like awk, as Ted Davis
suggested.
Tom Lavedas
===========
Thanks, Gawk worked but I could only do one file at a time. How can I
do all 10,000 files at once ending up with one file with 10,000 lines
of the data I need?
Also I tried to add two other lines, (1 and 56) to the search but it
would only do two searches not four. Is this possible?
Thank you very much
Or perhaps a different tool. i.e. VBScript
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fso.DeleteFile "output.txt"
On Error Goto 0
Set fout = fso.OpenTextFile("output.tmp",2,True)
Set f = fso.GetFolder(".")
Set fc = f.Files
For Each f1 in fc
If Lcase(Right(f1.name,3))="txt" Then
Set fin = fso.OpenTextFile(f1.name,1)
For i = 1 to 5:fin.SkipLine:Next
s1 = fin.ReadLine
For i = 7 to 146:fin.SkipLine:Next
s2 = fin.ReadLine
fout.WriteLine s1 & " " & s2
fin.Close
End If
Next
fout.Close
fso.MoveFile "output.tmp", "output.txt"
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
*** DOS users can do this with XSET. Depending on the DOS version, one
can use a FOR loop to either issue the commands for each file or have
FOR call a second batch file containing these lines:
TYPE %1 | XSET /LINE 6 LINE6
TYPE %1 | XSET /LINE 147 LINE147
ECHO %LINE6%%LINE147% >> BIGFILE.TXT
Don't forget to reset all variables to nothing at the end of
operations.
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/