logo
down
shadow

Addition of particular numbers in a file using awk or grep


Addition of particular numbers in a file using awk or grep

By : devguy
Date : November 17 2020, 11:55 AM
hop of those help? I am looking for something like this:
code :
awk '$1 != "Banana" {s+=$(NF-2)} END { print s}' RS= fruites.txt
awk '! match($1,"Banana") && match($NF, "found") {
    s += $(NF-2)} END { print s }' RS= fruites.txt


Share : facebook icon twitter icon
Addition of 2 numbers and give corresponding outputs depending on the number of digits got from the addition using C

Addition of 2 numbers and give corresponding outputs depending on the number of digits got from the addition using C


By : user1990461
Date : March 29 2020, 07:55 AM
I wish this help you As an idea. It is enough to check whether the result of the addition is less than 10 and greater than -10 if the numbers are signed.:)
grep the count of the numbers in a file

grep the count of the numbers in a file


By : Lineplay
Date : March 29 2020, 07:55 AM
it helps some times , To get count of lines with less than 5:
code :
grep -c '\<[^ ]\{1,5\}\>' file
grep -c '\<[^ ]\{5,7\}\>' file
Grep command - file names and numbers of repetitions of a certain word in each file printed in two columns

Grep command - file names and numbers of repetitions of a certain word in each file printed in two columns


By : Reena Mary
Date : March 29 2020, 07:55 AM
will be helpful for those in need You did a nice effort using cut. When you can solve a problem with cut than most of the time you have found a solid a quick solution.
In this case you need to fix the cutcommand what would give an ugly result.
code :
# Ugly cutting
grep -c "word" */*.txt | cut -d'/' -f2 | tr ':' '.' | cut -d"." -f1,3 | tr '.' ' '
# going weird
# Combine first colums
grep -c "word" */*.txt | cut -d'/' -f2 | cut -d"." -f1
# with second column
grep -c "word" */*.txt | cut -d'/' -f2 | cut -d":" -f2
# using paste and process substitution
paste -d" " <(grep -c "word" */*.txt | cut -d'/' -f2 | cut -d"." -f1) <(grep -c "word" */*.txt | cut -d'/' -f2 | cut -d":" -f2)
grep -c "word" */*.txt | sed 's#.*/##;s#\..*:# #'
# or shorter
grep -c "word" */*.txt | sed 's#.*/\([^.]*\).*:#\1 #'
is two's complement addition of two positive numbers the same as normal addition?

is two's complement addition of two positive numbers the same as normal addition?


By : Evgeny Zhdanyuk
Date : October 30 2020, 08:01 PM
To fix this issue There's no such thing as "two's complement addition of positive numbers" because two's complement is a way of storing negative numbers: -n is stored as ~n + 1, which is equivalent to 2^w - n where w is the width of the integer type.
Two's complement is designed for modulo 2^w arithmetic: (+a) + (-b) is represented as a + (2^w - b) = (a - b) + 2^w, which gives the correct answer of a-b after reduction modulo 2^w. Similarly, (-a) + (-b) is represented as (2^w - a) + (2^w - b) = (-a - b) + 2 * 2^w, which reduces to the expected -a - b.
Is addition of small numbers faster than addition of big ones?

Is addition of small numbers faster than addition of big ones?


By : Dickson Nkon
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The effects of specific optimizations will depend on your compiler. You should have a look at the assembly code generated in each case and compare what CPU instructions were generated. At the level of CPU, there shouldn't be any difference in performance dependent on the values you add if the same instructions are generated. The CPU has a clock signal and simple arithmetic operations will take the same number of clock ticks regardless of whether the operand's bits are ones or zeros if the same instructions are executed on the same sized operands. Memory effects may impact performance, but here the data is small enough for this to probably not matter much. In the disassembly you could check if your variables end up in registers. If not, one could wonder if with just a few variables effects which play an important role with larger data (like cache hits/misses, physical memory accesses etc.) also matter here. They might, as your CPU is capable of billions of arithmetic operations per second but RAM is an external device which is much slower. Regardless, such effects would be random and not depend on whether the values you add are large or small. Same should go for pipeline stalls, instruction reordering etc. In a series of experiments, performed at different times, the average time should be the same within a margin of error (the difference you get in release mode certainly falls into this category).
One possibility I see where there could be a difference would be a compiler which handled 64-bit numbers not directly by 64-bit instructions but using multiple 32-bit instructions. In such a case, a smart compiler might notice that the values you use in some loop can never grow beyond the limit of 32 bit numbers and issue instructions working only on a single 32 bit value instead of on two 32-bit values making up the 64-bit value. A look at the disassembly could reveal if that is the case.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org