mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Linux

Reply
 
Thread Tools
Old 2015-04-23, 21:51   #1
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

2·677 Posts
Default 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
pepi37 is online now   Reply With Quote
Old 2015-04-23, 21:57   #2
Mark Rose
 
Mark Rose's Avatar
 
"/X\(‘-‘)/X\"
Jan 2013

B6216 Posts
Default

You could easily add it back with sed:

grep -h 'is prime!' /pepi/p*/lresu0000.txt | cut -d! -f1 | sed 's/$/!/'
Mark Rose is offline   Reply With Quote
Old 2015-04-23, 21:58   #3
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×2,399 Posts
Default

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 (
Dubslow is offline   Reply With Quote
Old 2015-04-23, 21:59   #4
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

25128 Posts
Default

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
pepi37 is online now   Reply With Quote
Old 2015-04-23, 22:05   #5
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

66608 Posts
Default

Code:
cut -d\  -f1,3
There are 2 spaces after the "\"
paulunderwood is offline   Reply With Quote
Old 2015-04-23, 22:06   #6
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

135410 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
Code:
cut -d\  -f1,3
There are 2 spaces after the "\"
Sharp eyes!
pepi37 is online now   Reply With Quote
Old 2015-05-15, 13:31   #7
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

2×677 Posts
Default

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..
pepi37 is online now   Reply With Quote
Old 2015-05-15, 14:10   #8
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

2×11×157 Posts
Default

Quote:
Originally Posted by pepi37 View Post
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.
EdH is offline   Reply With Quote
Old 2015-05-15, 14:16   #9
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

101010010102 Posts
Default

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
pepi37 is online now   Reply With Quote
Old 2015-05-15, 15:11   #10
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

2·5·11·71 Posts
Default

Quote:
Originally Posted by EdH View Post
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.
Xyzzy is offline   Reply With Quote
Old 2015-05-15, 15:13   #11
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

2·5·11·71 Posts
Default

Quote:
Originally Posted by pepi37 View Post
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
Xyzzy is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sieving with powers of small primes in the Small Prime variation of the Quadratic Sieve mickfrancis Factoring 2 2016-05-06 08:13
Small primes kar_bon Riesel Prime Data Collecting (k*2^n-1) 3 2013-05-11 04:56
Small Primes Housemouse Math 2 2008-06-04 05:23
Small Primes for Octoproths <= 155 ValerieVonck Octoproth Search 100 2007-02-16 23:43
Generating Small Primes 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

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, 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.