mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PrimeNet (https://www.mersenneforum.org/forumdisplay.php?f=11)
-   -   convert files from srsieve/srfile into worktodo.txt (https://www.mersenneforum.org/showthread.php?t=19798)

Rincewind 2014-10-31 12:18

convert files from srsieve/srfile into worktodo.txt
 
Hi,

is there a way to convert the output from srsieve/srfile (.abcd .prp .pfgw) automaticaly into a worktodo.txt for mprime/prime95?

Mini-Geek 2014-10-31 14:00

If doing a little bit of manual work, you can use a text editor: In any decent text editor (e.g. Notepad++), use regex to find/replace, e.g.
[CODE]^(\d+) (\d+)$[/CODE]
replace with
[CODE]PRP=\1,2,\2,-1[/CODE]

will transform

[CODE]some header line
456 789456
789 456987[/CODE]

to

[CODE]some header line
PRP=456,2,789456,-1
PRP=789,2,456987,-1
[/CODE]

If you need it to be an automated script, you might do something like this pseudo-Python:
[CODE]for line in read(input_file):
# if it's an actual line and not a header
k, n = split(line)
print('PRP={},2,{},-1', k, n)[/CODE]

Dubslow 2014-10-31 15:13

[code]
import re
in_file = 'blah.abcd'
out = []
with open(in_file) as f:
for line in f.readlines():
if re.match(r'^(\d+) (\d+)$', line):
k, n = line.split()
out.append('PRP={},2,{},-1'.format(k, n))
out_file = 'worktodo.txt'
with open(out_file, 'w') as f:
f.write('\n'.join(out) + '\n')
[/code]

The loop could be written as an ultra-extended list comprehension:

[code]
out = ['PRP={},2,{},-1'.format(*line.split()) for line in f.readlines() if re.match(r'^(\d+) (\d+)$', line)]
[/code]

Rincewind 2014-10-31 17:18

That's great!

I thought about using 'sed' but regex and I are not the best friends ; )
Thank you both!

Batalov 2014-10-31 17:46

awk

For example
[FONT="Fixedsys"]awk '{print "PRP="$1",2,"$2",-1"}' infile > outfile[/FONT]
and then take care of the 1st line (the header) in an editor

Mark Rose 2014-10-31 19:07

[QUOTE=Batalov;386567]awk

For example
[FONT="Fixedsys"]awk '{print "PRP="$1",2,"$2",-1"}' infile > outfile[/FONT]
and then take care of the 1st line (the header) in an editor[/QUOTE]

awk '{if(NR==1){print;}else{print "PRP="$1",2,"$2",-1"}' infile >outfile

:)

Batalov 2014-10-31 19:19

Perfectionism notwithstanding, there's no limit what can be further beautified :)

If you have 400 lines in input and 8 cores for Prime95 to follow,

awk '{if(NR%50==1){print "[Worker #"int(NR/50)+1"]"} if(NR>1){print "PRP="$1",2,"$2",-1"}}' infile >outfile

Rincewind 2014-10-31 22:33

This is very helpful!

Is there a way to use sed or awk to create a file for n-cores where every nth-candidate is moved to a certain worker:

for example 4 cores:
[code]
candidate - > assigned worker
1 1
2 2
3 3
4 4
5 1
6 2
7 3
8 4
...
[/code]

This would mean that there are no (or only small) gaps between the n-values from the workers.

Batalov 2014-10-31 23:04

Here you will need a bit of perl (probably can be done in awk, but when you get out of one-line volume of code in awk you want to switch to perl). This takes one parameter (or 4 by default) and text on stdin, like this: ./split.pl 6 < aa.npg > worktodo.txt
[CODE]#!/usr/bin/perl -w

$N = (shift || 4);

@A = <>;

for($i=1;$i<=$N;$i++) {
print "[Worker #", $i, "]\n";
for($k=$i;$k<@A;$k+=$N) {
$A[$k] =~ /(\d+) (\d+)/;
print "PRP=$1,2,$2,-1\n";
}
}
[/CODE]
[B]Note[/B]: this, of course, assumes that the input if an .npg file or a .pfgw file and the first line of it is to be thrown away. Don't forget it or else you will lose the first line with a candidate (if you actually already stripped the header).

Rincewind 2014-11-01 11:47

Again: Thank you!
This will do it for me.


All times are UTC. The time now is 01:10.

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