![]() |
![]() |
#1 |
"Evan"
Dec 2020
Montreal
23·32 Posts |
![]()
As a part of the script I'm working on (https://www.mersenneforum.org/showthread.php?t=27185) for automating NFS polynomial optimization, for every line in a given file, I'm looking to convert a single line of space-delimited numbers into a set of lines, each with one of those numbers (discarding the last two), i.e.
Code:
120 -11281742212640 722045358858476258138115 2694891023958331982083306 -83933374113179207162110170423420169 -27085510659298648315702935344138665 51773992299728647 -130923698301412860609805316167401612 -1.26 1.024483e+25 Code:
n: input_number c5: 120 c4: -11281742212640 c3: 722045358858476258138115 c2: 2694891023958331982083306 c1: -83933374113179207162110170423420169 c0: -27085510659298648315702935344138665 Y1: 51773992299728647 Y0: -130923698301412860609805316167401612 |
![]() |
![]() |
![]() |
#2 |
Sep 2002
Database er0rr
5·829 Posts |
![]() Code:
#!/bin/bash while read line; do larray=($line) echo "n: input_number" echo "c5: ${larray[0]}" echo "c4: ${larray[1]}" echo "c3: ${larray[2]}" echo "c2: ${larray[3]}" echo "c1: ${larray[4]}" echo "c0: ${larray[5]}" echo "Y1: ${larray[6]}" echo "Y0: ${larray[7]}" done < $1 Last fiddled with by paulunderwood on 2021-10-05 at 19:56 |
![]() |
![]() |
![]() |
#3 | |
"Evan"
Dec 2020
Montreal
23·32 Posts |
![]() Quote:
convert_polys.sh: Code:
#!/bin/bash # Convert msieve raw poly to CADO format number=$2 while read line; do larray=($line) echo "n: $number" echo "c5: ${larray[0]}" echo "c4: ${larray[1]}" echo "c3: ${larray[2]}" echo "c2: ${larray[3]}" echo "c1: ${larray[4]}" echo "c0: ${larray[5]}" echo "Y1: ${larray[6]}" echo "Y0: ${larray[7]}" echo done < $1 Code:
... if [[ "$VERIFICATION_STRING" =~ $CADO_REGEX ]]; then echo File is valid sopt input. else echo Invalid input, attempting to reformat. # pass off to separate script, convert msieve to cado format ./convert_polys.sh $POLYFILE $NUMBER > formatted POLYFILE=formatted ... |
|
![]() |
![]() |
![]() |
#4 |
"Curtis"
Feb 2005
Riverside, CA
14A916 Posts |
![]()
Note that you may wish to name this mini-script something about degree 5, since it would not work in the case where the poly lines are degree 6 (GNFS 211-ish-plus).
Or is it best to just assume the script is working with degree 5 polys only? |
![]() |
![]() |
![]() |
#5 |
"Evan"
Dec 2020
Montreal
10010002 Posts |
![]()
Honestly, that totally slipped my mind. I'll probably make two separate versions, called by the main script based on the degree parameter.
|
![]() |
![]() |
![]() |
#6 |
"Ed Hall"
Dec 2009
Adirondack Mtns
25×3×47 Posts |
![]()
I modified my script to work all the way to degree 8, by checking the number of array elements and using if-then conditionals to add in the needed coefficients.
|
![]() |
![]() |
![]() |
#7 |
"Evan"
Dec 2020
Montreal
23·32 Posts |
![]()
another issue!
How would I reformat a set of lines given a certain order of initial characters? i.e. Code:
n: 1271515007705102652189952725761191819303345301747516657201545585841235185390068713842394904588907747685724022636366668603115951556046696630803051897639628872247236774090687993328825102782693109 Y0: -35164392518977695245121325949318512206 Y1: 330529894414407689 c0: -7834044196107389385481722033436772196487802910080 c1: 32695287468220878145255421865209242060304 c2: 166758603406144019739995422783832 c3: -374511489403856061344417 c4: -1148136776700228 c5: 189189 skew: 534376440.24 Code:
n: 1271515007705102652189952725761191819303345301747516657201545585841235185390068713842394904588907747685724022636366668603115951556046696630803051897639628872247236774090687993328825102782693109 c5: 189189 c4: -1148136776700228 c3: -374511489403856061344417 c2: 166758603406144019739995422783832 c1: 32695287468220878145255421865209242060304 c0: -7834044196107389385481722033436772196487802910080 Y1: 330529894414407689 Y0: -35164392518977695245121325949318512206 skew: 534376440.24 Last fiddled with by Plutie on 2021-10-06 at 22:45 Reason: fixed format |
![]() |
![]() |
![]() |
#8 |
Sep 2002
Database er0rr
100618 Posts |
![]() Code:
#!/bin/bash readarray lines < $1 echo ${lines[0]} i=1 j=${#lines[@]} while ! [[ ${lines[$i]} =~ "skew" ]]; do i=$(expr $i + 1) echo ${lines[$(expr $j - $i )]} done echo ${lines[$i]} |
![]() |
![]() |
![]() |
#9 | |
"Evan"
Dec 2020
Montreal
23×32 Posts |
![]() Quote:
Code:
... Y1: 330529894414407689 Y0: -17582196259488608100436846735568937674 1271515007705102652189952725761191819303345301747516657201545585841235185390068713842394904588907747685724022636366668603115951556046696630803051897639628872247236774090687993328825102782693109 skew: 256945061.15 |
|
![]() |
![]() |
![]() |
#10 |
Sep 2002
Database er0rr
5·829 Posts |
![]()
I don't understand how it loses "n:". The first line must be n and its value and not an empty line. It could be a better script, dropping "j".
Last fiddled with by paulunderwood on 2021-10-07 at 02:32 |
![]() |
![]() |
![]() |
#11 |
"Evan"
Dec 2020
Montreal
23·32 Posts |
![]() |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
PFGW scripting help | wpolly | Software | 8 | 2019-04-12 16:47 |
Bash on Ubuntu on Windows | henryzz | Software | 11 | 2017-07-28 21:24 |
Scripting startup on multiple systems | stebbo | Software | 5 | 2016-09-17 08:45 |
Could use some scripting help (windows) | Greebley | Aliquot Sequences | 1 | 2012-11-16 19:53 |
bash and HTTP? | Dubslow | Information & Answers | 11 | 2011-12-14 21:07 |