I seem to have gotten myself in over my head on this one. I need help combining lines together.
I have a text file containing 24,000 lines (exactly why I need awk) due to bad formatting it has separated the lines (ideally it should be 12,000 lines total).
Example of file:
... (2 Replies)
I am using:
ps -A -o command,%cpu
to get process and cpu usage figures. I want to use awk to split up the columns it returns. If I use:
awk '{print "Process: "$1"\nCPU Usage: "$NF"\n"}'
the $NF will get me the value in the last column, but if there is more than one word in the... (2 Replies)
It would be convenient to be able to combine awk tests. For example, suppose that I do this query:
awk '$1 != "Bob" || $1 != "Linda" {print $2}' datafileIs there a reasonable way to combine the conditions into a single statement? For example, in egrep, I can do:
egrep -v "Bob|Linda"... (4 Replies)
I have a file like this consisting of blocks separated by > of two number X and T
>
10 0
13 5.92346
16 10.3106
19 13.9672
22 16.9838
25 19.4407
28 21.4705
31 23.1547
34 24.6813
37 26.0695
40 27.3611
43 28.631
46 29.8366
49 30.9858
52 32.0934
55 33.1458 (6 Replies)
I have a pretty simple script below:
#!/bin/sh
for i in *.cfg
do
temp=`awk '/^InputDirectory=/' ${i}`
input_dir=`echo ${temp} | awk '{ print substr( $0, 16) }'`
echo ${input_dir}
done
As you can see its opening each cfg file and searching for the line that has "InputDirectory="... (3 Replies)
Hi experts,
I have a requirement, In which I need to display the first and last line of a zip file where the line starts with "L". I've writen the code like below using sed and awk.
gunzip -c 20110203.1104.gz | awk '$1 ~ "^L" {print substr($0,178,15)}' | sed -n '1p;$p'
Is it possible to do it... (8 Replies)
Hello UNIX Community,
I have file that contains the following data:
testAwk2.csv
rabbit penguin goat
giraffe emu ostrich
hyena elephant panda
dog cat pig
lizard snake antelope
platypus tiger cheetah
lion rhino spider
I then find the character length of the... (1 Reply)
i have a datafile that has several lines that look like this:
2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4
using the following command:
awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
the following code works perfectly for me:
# AWK 1
gawk -F, '/,'${ThisMonthDOW}' '${ThisMonthMON}' :: '${ThisMonthYEA}',/ {
if (NF == 10)
... (6 Replies)
Discussion started by: SkySmart
6 Replies
LEARN ABOUT DEBIAN
statistics::basic::variance
Statistics::Basic::Variance(3pm) User Contributed Perl Documentation Statistics::Basic::Variance(3pm)NAME
Statistics::Basic::Variance - find the variance of a list
SYNOPSIS
Invoke it this way:
my $variance = variance(1,2,3);
Or this way:
my $v1 = vector(1,2,3);
my $var = var($v1);
And then either query the values or print them like so:
print "The variance of $v1: $variance
";
my $vq = $var->query;
my $v0 = 0+$var;
Create a 20 point "moving" variance like so:
use Statistics::Basic qw(:all nofill);
my $sth = $dbh->prepare("select col1 from data where something");
my $len = 20;
my $var = var()->set_size($len);
$sth->execute or die $dbh->errstr;
$sth->bind_columns( my $val ) or die $dbh->errstr;
while( $sth->fetch ) {
$var->insert( $val );
if( defined( my $v = $var->query ) ) {
print "Variance: $v
";
}
# This would also work:
# print "Variance: $v
" if $var->query_filled;
}
METHODS
new()
The constructor takes a list of values, a single array ref, or a single Statistics::Basic::Vector as arguments. It returns a
Statistics::Basic::Variance object.
Note: normally you'd use the mean() constructor, rather than building these by hand using "new()".
query_mean()
Returns the Statistics::Basic::Mean object used in the variance computation.
_OVB::import()
This module also inherits all the overloads and methods from Statistics::Basic::_OneVectorBase.
AUTHOR
Paul Miller "<jettero@cpan.org>"
I am using this software in my own projects... If you find bugs, please please please let me know. :) Actually, let me know if you find it
handy at all. Half the fun of releasing this stuff is knowing that people use it.
OVERLOADS
This object is overloaded. It tries to return an appropriate string for the calculation or the value of the computation in numeric
context.
In boolean context, this object is always true (even when empty).
COPYRIGHT
Copyright 2012 Paul Miller -- Licensed under the LGPL
SEE ALSO perl(1), Statistics::Basic, Statistics::Basic::_OneVectorBase, Statistics::Basic::Vector
perl v5.14.2 2012-01-23 Statistics::Basic::Variance(3pm)