mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Linux (https://www.mersenneforum.org/forumdisplay.php?f=39)
-   -   what I do wrong (https://www.mersenneforum.org/showthread.php?t=20353)

pepi37 2015-07-12 00:54

what I do wrong
 
results.txt
---------------------------------------------------------------------------
[Sat Jul 11 23:04:00 2015]
2*11^13355+1 is not prime. RES64: 2BC6AF8D47953C43. We8: 68566856,00000000
2*11^13356+1 is not prime. RES64: 27FF3175F85CE71C. We8: 68586858,00000000
2*11^13357+1 is not prime. RES64: 0FE8C886B553D211. We8: 685A685A,00000000
2*11^13359+1 is a probable prime! We8: 685E685E,00000000
---------------------------------------------------------------------------

clear
[COLOR=Magenta]echo
echo " **** UP TIME **** "
echo " " [QUOTE] [COLOR=Black]to see does computer work all time[/COLOR][/QUOTE]uptime | sed 's/^.* up \+\(.\+\), \+[0-9] user.*$/\1/'
echo " "[/COLOR]
[COLOR=SeaGreen]echo " **** PRP FOUND **** "
echo " " [QUOTE] [COLOR=Black]check is anywhere "prime!" and display it [/COLOR][/QUOTE]grep -h 'prime!' /pepi/mprime/results.txt | cut -d"W" -f1
grep -h 'prime!' /pepi/res.txt | cut -d"W" -f1
grep -h 'prime!' /pepi/prp.txt | cut -d"W" -f1
echo " "[/COLOR]
[COLOR=DeepSkyBlue]echo "COLLECTING RESULTS"
cat /pepi/mprime/results.txt [B]>>[/B] res.txt
for fname in /pepi/mprime/results.txt [QUOTE] [COLOR=Black]collect results to file res.txt and delete results.txt[/COLOR][/QUOTE]do
> $fname
done
echo "COLLECTING DONE "
echo " "[/COLOR]
grep -h 'prime.' /pepi/res.txt | cut -d"W" -f1 > res.txt [QUOTE] remove part of line I dont need[/QUOTE]wc -l < /pepi/res.txt [QUOTE] count lines in res.txt and display result[/QUOTE]grep "!" /pepi/res.txt >> prp.txt [QUOTE]copy line with "!" to file prp.txt[/QUOTE]echo " "
echo NUMBER of PRIMES
wc -l prp.txt | cut -d "p" -f1 [QUOTE]counts number of lines in prp.txt and display result[/QUOTE]
sleep 2
exit


What I do wrong?
This is my script that collects results from file, remove part of lines, and wrote that in res.txt and prp.txt
And all is ok if there is data in "initial file"- results.txt, this script do exactly what I wont
But if results.txt is empty, then script also delete content of res.txt?
Why, where is error?
Thanks for any advice!

Mark Rose 2015-07-12 04:27

[code]grep -h 'prime.' /pepi/res.txt | cut -d"W" -f1 > res.txt[/code]

The single > will always overwrite the file.

You could test if the file is empty at the beginning and exit or whatever:

[code]
if [[ ! -s /pepi/res.txt ]] ; then exit ; fi
[/code]

Dubslow 2015-07-12 05:16

Or use ">>" (appends without overwriting)

pepi37 2015-07-12 08:10

[QUOTE=Dubslow;405704]Or use ">>" (appends without overwriting)[/QUOTE]

If I do that then number of lines id doubled in every checking, so that is not solution.
But I dont know why is doubling if initial file is empty.

[QUOTE]if [[ ! -s /pepi/res.txt ]] ; then exit ; fiT[/QUOTE]

his throw some error, so it doesnot work :(

pepi37 2015-07-12 09:13

I found where error was.
I must create temporary file and then delete it

grep -h 'prime.' /pepi[B]/resu.txt[/B] | cut -d"W" -f1 >> results.txt
[B]rm resu.txt[/B]

Now all is perfect!
Thanks for help!


All times are UTC. The time now is 08:30.

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