mersenneforum.org Small script for primes (SOLVED)
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

 2015-04-23, 21:51 #1 pepi37     Dec 2011 After milion nines:) 2·677 Posts Small script for primes (SOLVED) Hi to all I made small sh script for searching primes inside RES file echo "**** PRIMES FOUND ****" echo " " grep -h 'is prime!' /pepi/p*/lresu0000.txt | cut -d! -f1 echo " " and if I in lresu0000.txt have output as 92*10^5573-1 is prime! (5575 decimal digits, P = 4) Time : 413.977 ms. as result I got 92*10^5573-1 is prime but I wont to get 92*10^5573-1 is prime! ( yes I wont ! mark) So where is problem If I use cut -d( - got syntax error ( ( is not expected) What I write wrong? Thanks Last fiddled with by pepi37 on 2015-04-23 at 22:05
 2015-04-23, 21:57 #2 Mark Rose     "/X\(‘-‘)/X\" Jan 2013 B6216 Posts You could easily add it back with sed: grep -h 'is prime!' /pepi/p*/lresu0000.txt | cut -d! -f1 | sed 's/$/!/'  2015-04-23, 21:58 #3 Dubslow Basketry That Evening! "Bunslow the Bold" Jun 2011 40  2015-04-23, 21:59 #4 pepi37 Dec 2011 After milion nines:) 25128 Posts grep -h 'is prime!' /pepi/p*/lresu0000.txt | cut -d! -f1 | sed 's/$/!/' Put the ( in quotes. It's a special shell character, so sh isn't interpreting it as a simple argument to cut. Quoting it tells the shell you just want a literal ( Both works perfect! WOW so many answers in two minutes Thanks to all! Last fiddled with by pepi37 on 2015-04-23 at 22:04
 2015-04-23, 22:05 #5 paulunderwood     Sep 2002 Database er0rr 66608 Posts Code: cut -d\ -f1,3 There are 2 spaces after the "\"
2015-04-23, 22:06   #6
pepi37

Dec 2011
After milion nines:)

135410 Posts

Quote:
 Originally Posted by paulunderwood Code: cut -d\ -f1,3 There are 2 spaces after the "\"
Sharp eyes!

 2015-05-15, 13:31 #7 pepi37     Dec 2011 After milion nines:) 2×677 Posts I will write in this topic ( to make forum clean) I have four dir named p1 p2 p3 p4 Inside every dir is file called lresults.txt I wont to make small sh script to copy content of all lresults.txt in one big file called results.txt outside those dir and after that deleting all lresults.txt inside all dir..
2015-05-15, 14:10   #8
EdH

"Ed Hall"
Dec 2009

2×11×157 Posts

Quote:
 Originally Posted by pepi37 I will write in this topic ( to make forum clean) I have four dir named p1 p2 p3 p4 Inside every dir is file called lresults.txt I wont to make small sh script to copy content of all lresults.txt in one big file called results.txt outside those dir and after that deleting all lresults.txt inside all dir..
Try:
Code:
cat p*/lresults.txt > results.txt
rm p*/lresults.txt
Note: If you have any other p* directories with lresults.txt in them, they will also be included in the operation.

 2015-05-15, 14:16 #9 pepi37     Dec 2011 After milion nines:) 101010010102 Posts EDH, works perfect! Thanks! And if I wont to delete content of lresults.txt but not lresults.txt itself, what to change? found solution for fname in /pepi/p*/lresults.txt do > $fname done :) Last fiddled with by pepi37 on 2015-05-15 at 15:13 Reason: add more info 2015-05-15, 15:11 #10 Xyzzy "Mike" Aug 2002 2·5·11·71 Posts Quote:  Originally Posted by EdH Try: Code: cat p*/lresults.txt > results.txt rm p*/lresults.txt Note: If you have any other p* directories with lresults.txt in them, they will also be included in the operation. A safer approach is: Code: cat p*/lresults.txt > results.txt && rm p*/lresults.txt This code only runs the "second line" if the "first line" is successful. A simple example that illustrates this concept: Code: $ whoami
m

$cd /$ touch a && ls
touch: cannot touch ‘a’: Permission denied

touch a; ls
touch: cannot touch ‘a’: Permission denied
bin  boot  dev  etc  home  initrd.img  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  vmlinuz
The first command verifies that we are not root. The third command is conditional and the fourth command runs everything.

2015-05-15, 15:13   #11
Xyzzy

"Mike"
Aug 2002

2·5·11·71 Posts

Quote:
 Originally Posted by pepi37 And if I wont to delete content of lresults.txt but not lresults.txt itself, what to change?
Code:
cat /dev/null > p*/lresults.txt

 Similar Threads Thread Thread Starter Forum Replies Last Post mickfrancis Factoring 2 2016-05-06 08:13 kar_bon Riesel Prime Data Collecting (k*2^n-1) 3 2013-05-11 04:56 Housemouse Math 2 2008-06-04 05:23 ValerieVonck Octoproth Search 100 2007-02-16 23:43 wblipp Software 2 2005-01-05 13:29

All times are UTC. The time now is 17:21.

Sun Nov 29 17:21:34 UTC 2020 up 80 days, 14:32, 4 users, load averages: 1.20, 1.52, 1.45