mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Linux (https://www.mersenneforum.org/forumdisplay.php?f=39)
-   -   Small script for primes (SOLVED) (https://www.mersenneforum.org/showthread.php?t=20195)

pepi37 2015-04-23 21:51

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[SIZE=3][COLOR=Red][B]![/B][/COLOR][/SIZE] ( yes I wont ! mark)

So where is problem
If I use cut -d( - got syntax error ( [COLOR=Red]([/COLOR] is not expected)
What I write wrong?

Thanks

Mark Rose 2015-04-23 21:57

You could easily add it back with sed:

grep -h 'is prime!' /pepi/p*/lresu0000.txt | cut -d! -f1 | sed 's/$/!/'

Dubslow 2015-04-23 21:58

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 (

pepi37 2015-04-23 21:59

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!

paulunderwood 2015-04-23 22:05

[CODE]cut -d\ -f1,3[/CODE]

There are 2 spaces after the "\" :smile:

pepi37 2015-04-23 22:06

[QUOTE=paulunderwood;400755][CODE]cut -d\ -f1,3[/CODE]There are 2 spaces after the "\" :smile:[/QUOTE]
Sharp eyes! :bow::bow::bow:

pepi37 2015-05-15 13:31

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..

EdH 2015-05-15 14:10

[QUOTE=pepi37;402339]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..[/QUOTE]

Try:
[code]
cat p*/lresults.txt > results.txt
rm p*/lresults.txt
[/code]

Note: If you have any other p* directories with lresults.txt in them, they will also be included in the operation.

pepi37 2015-05-15 14:16

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 :)

Xyzzy 2015-05-15 15:11

[QUOTE=EdH;402340]Try:
[code]
cat p*/lresults.txt > results.txt
rm p*/lresults.txt
[/code]Note: If you have any other p* directories with lresults.txt in them, they will also be included in the operation.[/QUOTE]
A safer approach is:

[CODE]cat p*/lresults.txt > results.txt && rm p*/lresults.txt[/CODE]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[/CODE]The first command verifies that we are not root. The third command is conditional and the fourth command runs everything.

Xyzzy 2015-05-15 15:13

[QUOTE=pepi37;402341]And if I wont to delete content of lresults.txt but not lresults.txt itself, what to change?[/QUOTE][CODE]cat /dev/null > p*/lresults.txt[/CODE]


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

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