Search Results

Search: Posts Made By: rogeriog.em
7,577
Posted By Yoda
If you want to disregard the first column, just...
If you want to disregard the first column, just print the sum:
print A[k]


By default, the order in which a for (i in array) loop scans an array is not defined; it is generally based upon the...
7,577
Posted By Yoda
awk ' # Create an associative array: A...
awk '
# Create an associative array: A for which value is sum of $2 and indexed by $1
{
A[$1] += $2
}

# End Block
END {
# For...
7,577
Posted By RudiC
Depends how your files are structured, and how...
Depends how your files are structured, and how many of them are present. Try sth like (untested):awk '{RES[$1]+=$2} END {for (n in RES) print n, RES[n]}' file*
7,577
Posted By Yoda
awk '{A[$1]+=$2}END{for(k in A) print k,A[k]}'...
awk '{A[$1]+=$2}END{for(k in A) print k,A[k]}' file*
1,017
Posted By RudiC
Which means that his sub($0,0) reads...
Which means that his sub($0,0) reads sub($0,0,$0)and should work fine. I'd rather guess it's to do with the E+which in regexes means "one or more occurrences of E", and the + is consumed, so it does...
1,017
Posted By Don Cragun
Note that if all you want to do is replace every...
Note that if all you want to do is replace every input line with a 0, there is no need for sub():
awk '{print 0}' infile > outfile
or
sed 's/.*/0/' infile > outfile
or
while read -r x...
1,017
Posted By Yoda
The syntax of sub function is: sub ( regex,...
The syntax of sub function is:
sub ( regex, replacement, target)
So it should be:
sub( /.*/, 0, $0 )
Also note that target is an optional argument. If target is not supplied it will use $0...
9,748
Posted By Scrutinizer
Perhaps you were looking for CONVFMT ? awk...
Perhaps you were looking for CONVFMT ?
awk '{for(i=1; i<=NF; i++) $i+=0}1' CONVFMT="%.10f" file

Output:
-6.8908090183 3.4934889171 1.4798836784 -2.2970763541 -3.4934236471 -4.4375847324...
9,748
Posted By Yoda
X is nothing but an undefined variable. So...
X is nothing but an undefined variable. So substituting with X is same as substituting with null.

1 == true and 0 == false. When true, the default awk action is to print the record. So that 1 is...
9,748
Posted By RudiC
Try awk '{for (i=1; i<=NF; i++)...
Try awk '{for (i=1; i<=NF; i++) sub(/...........$/,"",$i)}1' fileI was trying to set and use the OFMT variable (as you obviously want to modify long mantissae), but this did not work in my linux/mawk...
9,748
Posted By Yoda
awk '{for(i=1;i<=NF;i++)...
awk '{for(i=1;i<=NF;i++) sub(/...........$/,X,$i)}1' file
Showing results 1 to 11 of 11

 
All times are GMT -4. The time now is 09:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy