mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2006-12-07, 01:19   #1
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

67178 Posts
Default getting and parsing last line (windows)

Under Windows, I have a log file which has, for example, the last line:

10000000000+99905361 is 5-prp

I want to use this to start the program again with parameter "-s99905361". Please help.
paulunderwood is offline   Reply With Quote
Old 2006-12-07, 05:03   #2
wblipp
 
wblipp's Avatar
 
"William"
May 2003
New Haven

44708 Posts
Default

What tools are permitted? I'd probably use PERL to write a batch file, and then wrap that in another batch file that calls the PERL then calls the PERL-created batch file. A port of the UNIX tool "tail" would also be handy. If it must be stock Windows, it might be possible to cook something up with a batch file named 10000000000 and the find command, but that would take some playing around to make it work.
wblipp is offline   Reply With Quote
Old 2006-12-07, 13:39   #3
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

67178 Posts
Default

Windows without Perl, I am affraid. I am pretty sure there is a way, by scanning the log file and storing each line into a variable so that when the file has been read the variable will contain the last line. Then it is a question of parsing the contents of the variable. But the details escape me
paulunderwood is offline   Reply With Quote
Old 2006-12-07, 15:04   #4
antiroach
 
antiroach's Avatar
 
Jun 2003

22×61 Posts
Default

Are you able to install cygwin? If so you can use the standard linux tools to accomplish this.
antiroach is offline   Reply With Quote
Old 2006-12-07, 15:06   #5
antiroach
 
antiroach's Avatar
 
Jun 2003

22×61 Posts
Default

Are you able to install cygwin? If so you can use the standard linux tools to accomplish this. Or you can always write up a C program to do this.
antiroach is offline   Reply With Quote
Old 2006-12-07, 15:17   #6
Ken_g6
 
Ken_g6's Avatar
 
Jan 2005
Caught in a sieve

1100010112 Posts
Default

I don't see you getting away with this from a batch file without at least sed. Maybe tail, too, if you can find it.

Alternativley, some VBScript might do it for you. I know you can parse a line with a RegExp, and start a program with "SystemUtil.Run", but I don't know how to open a file in VBScript.

Edit: Here's how.

Last fiddled with by Ken_g6 on 2006-12-07 at 15:26
Ken_g6 is offline   Reply With Quote
Old 2006-12-07, 17:36   #7
wblipp
 
wblipp's Avatar
 
"William"
May 2003
New Haven

236010 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
by scanning the log file and storing each line into a variable
The hard part of doing this with no addon tools is getting ANY line of the log file into a variable. Back in DOS 4.1 the standard trick was to treat the first token of the log file as a batch file name and execute the log file, causing the remaining tokens on the line to be positional parameters of the batch file. You don't know the first token, "10000000000+99905361" in your example, so that doesn't work directly.

It's possible that recent versions of Windows include a command that will read input, but I don't know of any. The best I've been able to concoct uses three key ideas:
1. Using findstr to get a prefix on the line which is shell executable
2. Using variable string substitution to replace the embedded "-" with a blank
3. Redirecting output to files with the file extension ".bat" so that you can then treat the output as a shell script.

The steps are:

1. make a copy of the log with the name "Call A.". Include the blank and have the file extension be blank.

2. create filelist.txt with the single line "Call A ". No quotes in the file, but be sure the blank is after the A.

3. findstr /Fflist.txt "PSP" > b.bat
This creates a file where every line begins Call A,

4. Create a file named a.bat that has
echo off
set X = %1
echo d %X:-= % > c.bat

every time this runs, it overwites c.bat with a line that has d then two tokens parsed from the first token

5. Create a file named d.bat that has
ProgramName -s%2

6. After the findstr, use "Call b.bat"

7. After the b.bat, "Call c.bat"

This can be cleaned up in a few ways - some of the batch files can be replaced with calls to CMD, or some of the batch files can be combined with labels and flags.

And of course it's MUCH cleaner to copy off the internet a sed and tail program that work in windows.

Last fiddled with by wblipp on 2006-12-07 at 17:38 Reason: typo
wblipp is offline   Reply With Quote
Old 2006-12-07, 18:50   #8
Uncwilly
6809 > 6502
 
Uncwilly's Avatar
 
"""""""""""""""""""
Aug 2003
101×103 Posts

220078 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
10000000000+99905361 is 5-prp
Will "10000000000+" always be part of the last line? We assume that it is not unique to the last line.
Uncwilly is online now   Reply With Quote
Old 2006-12-07, 19:36   #9
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

5·7·101 Posts
Default

Quote:
Originally Posted by Uncwilly View Post
Will "10000000000+" always be part of the last line? We assume that it is not unique to the last line.
Every line has "10000000000+".

It is beginning to look like I will need some extra-windows program, but I am studying William's solution...

Also, I will revise some DOS programming, hoping that this will still work in XP.
paulunderwood is offline   Reply With Quote
Old 2006-12-07, 21:20   #10
Uncwilly
6809 > 6502
 
Uncwilly's Avatar
 
"""""""""""""""""""
Aug 2003
101×103 Posts

23×401 Posts
Default

If we were still in Win3, we could use recorder. But a .vbs could do it.
Use it to fire up Note/WordPad. Ctrl-end to the bottom of the file, move right, highlight, ctrl-c, etc. You can even use it to launch your app.

See this link:
http://msdn2.microsoft.com/en-us/library/8c6yea83.aspx
Uncwilly is online now   Reply With Quote
Old 2006-12-07, 21:28   #11
smh
 
smh's Avatar
 
"Sander"
Oct 2002
52.345322,5.52471

29×41 Posts
Default

I was going to suggest edlin, but i can't figure out how to use ^Z in a batch file.

Assuming you have a file with only the prp's in it (findstr prp out.txt > prp.txt)

edlin prp.txt

1R10000000000+^Zprogram -S
1R is 5-prp^Z
e

The ^Z is a CTRL-Z

If i use a batch file it's always seen as a normal ^Z.

There are windows versions of most unix commands online though
smh is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows command line mu5tan6 Software 14 2015-03-20 17:21
Windows 7 Windows Update & Prime95 issue!!! Unregistered Information & Answers 14 2010-04-10 21:47
[Bug] Wrong parsing some results of manual testing klajok PrimeNet 2 2008-12-17 18:11
MultiSieve from the command line (on Windows) monst Software 7 2007-12-18 02:37
E=6 in P-1 result line S485122 Software 4 2007-01-28 04:02

All times are UTC. The time now is 16:27.

Thu Jan 28 16:27:17 UTC 2021 up 56 days, 12:38, 0 users, load averages: 5.13, 4.86, 4.66

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.