Hi,
I am trying to extracting the sum of all varibles listed in a file.
The code is as follows
##### FILE1 ########
Value1:2
Value2:2
Value3:6
Value4:5
##### shell script ######
#!/bin/sh
total=0 (2 Replies)
Hi,consider this fields,
$1 $2 $3
981 0 1
984 0 4
985 1 0
987 0 2
990 0 0
993 0 3
995 2 0
996 0 1
999 0 4
for each occurence of zero in column $2 and $3 I need to sum $1 fields, so for example, in this piece of code the result of $1 is 8910. I'm sure... (2 Replies)
Hi Experts,
I am adding a column of numbers with awk , however not getting correct output:
# awk '{sum+=$1} END {print sum}' datafile
2.15291e+06
How can I getthe output like : 2152910
Thank you..
# awk '{sum+=$1} END {print sum}' datafile
2.15079e+06 (3 Replies)
Hi all,
I need to sum values for fields in a delimited file as below:
2010-03-05|||
2010-03-05|||123
2010-03-05|467.621|369.532|
2010-03-06|||
2010-03-06||2|
2010-03-06|||444
2010-03-07|||
2010-03-07|||
2010-03-07|655.456|1019.301|
Code used is:
nawk -F "|" ' { sum +=... (7 Replies)
Hi,
I am unable sum of each column in the loop usng awk command.
Awk is not allowing the parameters in the command.
i am facing the below error.
awk: 0602-562 Field $() is not correct.
Source file
abc.txt
100,200,300,400,500,600,700,800,900
101,201,301,401,501,601,701,801,901
... (1 Reply)
Hi,
I have a file with header, detail and trailer records.
HDR|111
DTL|abc|100|xyz
DTL|abc|50|xyz
TRL|150
I need to add the values in 3rd field from DTL records.
Using awk, I am doing it as follows:
awk -F'|' '$1=="DTL"{a += $3} END {print a}' <source_file>
However, I want to... (3 Replies)
Hi
i have to calculate some numbers, column by column.
Herfore i used a for-loop..
for i in {4..26};do awk -F"," '{x'$i'+=$'$i'}END{print '$i'"\t" x'$i'}' file.tmp;done
----- printout -----
4 660905240
5 71205272
6 8.26169e+07
7 8.85961e+07
8 8.60936e+07
9 7.42238e+07
10 5.6051e+07... (7 Replies)
Hi all,
I have one host i need to run in loop to check the capacity from different frame and get the output to one file and sum it and convert to TB
this is Code
#!/bin/ksh
DATE=`date '+%d%m%y'`
for f in `cat /home/esx-capacity/esx-host.txt`
do
for g in `cat /home/esx-capacity/frame`... (10 Replies)
Discussion started by: ranjancom2000
10 Replies
LEARN ABOUT NETBSD
atomic_ops
ATOMIC_OPS(3) BSD Library Functions Manual ATOMIC_OPS(3)NAME
atomic_ops -- atomic memory operations
SYNOPSIS
#include <sys/atomic.h>
DESCRIPTION
The atomic_ops family of functions provide atomic memory operations. There are 7 classes of atomic memory operations available:
atomic_add(3) These functions perform atomic addition.
atomic_and(3) These functions perform atomic logical ``and''.
atomic_cas(3) These functions perform atomic compare-and-swap.
atomic_dec(3) These functions perform atomic decrement.
atomic_inc(3) These functions perform atomic increment.
atomic_or(3) These functions perform atomic logical ``or''.
atomic_swap(3) These functions perform atomic swap.
Synchronization Mechanisms
Where the architecture does not provide hardware support for atomic compare and swap (CAS), atomicity is provided by a restartable sequence
or by a spinlock. The chosen method is not ordinarily distinguishable by or visible to users of the interface. The following architectures
can be assumed to provide CAS in hardware: alpha, amd64, i386, powerpc, powerpc64, sparc64.
Scope and Restrictions
If hardware CAS is available, the atomic operations are globally atomic: operations within a memory region shared between processes are guar-
anteed to be performed atomically. If hardware CAS is not available, it may only be assumed that the operations are atomic with respect to
threads in the same process. Additionally, if hardware CAS is not available, the atomic operations must not be used within a signal handler.
Users of atomic memory operations should not make assumptions about how the memory access is performed (specifically, the width of the memory
access). For this reason, applications making use of atomic memory operations should limit their use to regular memory. The results of
using atomic memory operations on anything other than regular memory are undefined.
Users of atomic memory operations should take care to modify any given memory location either entirely with atomic operations or entirely
with some other synchronization mechanism. Intermixing of atomic operations with other synchronization mechanisms for the same memory loca-
tion results in undefined behavior.
Visibility and Ordering of Memory Accesses
If hardware CAS is available, stores to the target memory location by an atomic operation will reach global visibility before the operation
completes. If hardware CAS is not available, the store may not reach global visibility until some time after the atomic operation has com-
pleted. However, in all cases a subsequent atomic operation on the same memory cell will be delayed until the result of any preceeding oper-
ation has reached global visibility.
Atomic operations are strongly ordered with respect to each other. The global visibility of other loads and stores before and after an
atomic operation is undefined. Applications that require synchronization of loads and stores with respect to an atomic operation must use
memory barriers. See membar_ops(3).
Performance
Because atomic memory operations require expensive synchronization at the hardware level, applications should take care to minimize their
use. In certain cases, it may be more appropriate to use a mutex, especially if more than one memory location will be modified.
SEE ALSO atomic_add(3), atomic_and(3), atomic_cas(3), atomic_dec(3), atomic_inc(3), atomic_or(3), atomic_swap(3), membar_ops(3)HISTORY
The atomic_ops functions first appeared in NetBSD 5.0.
BSD April 14, 2010 BSD