![]() |
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 |
You could easily add it back with sed:
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 (
|
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! |
[CODE]cut -d\ -f1,3[/CODE]
There are 2 spaces after the "\" :smile: |
[QUOTE=paulunderwood;400755][CODE]cut -d\ -f1,3[/CODE]There are 2 spaces after the "\" :smile:[/QUOTE]
Sharp eyes! :bow::bow::bow: |
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=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. |
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 :) |
[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. |
[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.