Sponsored Content
Top Forums Shell Programming and Scripting Calculating average for every Nth line in the Nth column Post 302622493 by ncwxpanther on Thursday 12th of April 2012 08:17:14 AM
Old 04-12-2012
Calculating average for every Nth line in the Nth column

Is there an awk script that can easily perform the following operation?

I have a data file that is in the format of
Code:
1944-12,5.6
1945-01,9.8
1945-02,6.7
1945-03,9.3
1945-04,5.9
1945-05,0.7
1945-06,0.0
1945-07,0.0
1945-08,0.0
1945-09,0.0
1945-10,0.2
1945-11,10.5
1945-12,22.3
1946-01,35.2
1946-02,13.4

I need to find the average of the values contained within -01, -02, and -03.

For instance the average of
Code:
1945-01,9.8
1945-02,6.7
1945-03,9.3

Would output
Code:
1945-03, 8.6

Any help would be appreciative.
Thanks!

Last edited by Franklin52; 04-12-2012 at 09:18 AM.. Reason: Please use code tags for code and data samples, thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Editing 1st or nth column

Hi, I have a file whick is pipe delimited : 100| alpha| tabgo|watch| |||| 444444 | alpha| tabgo|watch| |||| 444444 | sweden |tabgo|watch| |||| 444444 | US| tabgo|watch| |||| 444444 100| factory| tabgo|watch| |||| 444444 | ABC| tabgo|watch| |||| 444444 | launch| tabgo|watch| ||||... (4 Replies)
Discussion started by: darshanw
4 Replies

2. Shell Programming and Scripting

get 3rd column of nth line

hi; i have a file.txt and its 9th, 10th and 11th line lines are: RbsLocalCell=S2C1 maxPortIP 4 (this is 9th line) RbsLocalCell=S3C1 maxPortIP 4 (this is 10th line) RbsLocalCell=S1C1 ... (11 Replies)
Discussion started by: gc_sw
11 Replies

3. Shell Programming and Scripting

Finding Nth Column

Please help me how can I display every nth field present in a "|" delimited file. Ex: If a have a file with data as a|b|c|d|e|f|g|h|k|l|m|n I want to display every 3rd feild which means the output should be c f k n Please help me. (1 Reply)
Discussion started by: ngkumar
1 Replies

4. Shell Programming and Scripting

Using AWK to find top Nth values in Nth column

I have an awk script to find the maximum value of the 2nd column of a 2 column datafile, but I need to find the top 5 maximum values of the 2nd column. Here is the script that works for the maximum value. awk 'BEGIN { subjectmax=$1 ; max=0} $2 >= max {subjectmax=$1 ; max=$2} END {print... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

5. Shell Programming and Scripting

awk to search for specific line and replace nth column

I need to be able to search for a string in the first column and if that string exists than replace the nth column with "-9.99". AW12000012012 2.38 1.51 3.01 1.66 0.90 0.91 1.22 0.82 0.57 1.67 2.31 3.63 0.00 AW12000012013 1.52 0.90 1.20 1.34 1.21 0.67 ... (14 Replies)
Discussion started by: ncwxpanther
14 Replies

6. Shell Programming and Scripting

Replace a value of Nth field of nth row

Using Awk, how can I achieve the following? I have set of record numbers, for which, I have to replace the nth field with some values, say spaces. Eg: Set of Records : 4,9,10,55,89,etc I have to change the 8th field of all the above set of records to spaces (10 spaces). Its a delimited... (1 Reply)
Discussion started by: deepakwins
1 Replies

7. Shell Programming and Scripting

Replace nth to nth character?

Hi I got the following problem and I wonder if some could please help me out? I'd like to replace character 8 - 16 , 16 - 24 cat file ... (2 Replies)
Discussion started by: stinkefisch
2 Replies

8. Shell Programming and Scripting

Taking nth column and putting its value in n+1 column using awk

Hello Members, Need your expert opinion how to tackle below. I have an input file that looks like below: USS|AWCC|AFGAW|93|70 USSAA|Roshan TDCA|AFGTD|93|72,79 ALB|Vodafone|ALBVF|355|69 ALGEE|Wataniya (Nedjma)|DZAWT|213|50,550 I like output file in below format: ... (7 Replies)
Discussion started by: umarsatti
7 Replies

9. UNIX for Dummies Questions & Answers

Getting the lines with nth column non-null

Hi, I have a huge list of archives (.gz). Each archive is about 40MB. A file is generated every minute so if I want to analyze the data for 1 hour I get already 60 files for example. These are text files, ';' separated, each line having about 300 fields (columns). What I need to do is to... (11 Replies)
Discussion started by: Nenad
11 Replies

10. Shell Programming and Scripting

Replace Value of nth Column of Each Line Using Array

Hello All, I am writing a shell script with following requirement: 1. I have one input file as below CHE01,A,MSC,INO CHE02,B,NST,INC CHE03,C,STM,INP 2. In shell script I have predefined array as below: Array1={A, B, C} Array2= {U09, C04, A054} (6 Replies)
Discussion started by: angshuman
6 Replies
QHttpHeader(3qt)														  QHttpHeader(3qt)

NAME
QHttpHeader - Header information for HTTP SYNOPSIS
#include <qhttp.h> Inherited by QHttpResponseHeader and QHttpRequestHeader. Public Members QHttpHeader () QHttpHeader ( const QHttpHeader & header ) QHttpHeader ( const QString & str ) virtual ~QHttpHeader () QHttpHeader & operator= ( const QHttpHeader & h ) QString value ( const QString & key ) const void setValue ( const QString & key, const QString & value ) void removeValue ( const QString & key ) QStringList keys () const bool hasKey ( const QString & key ) const bool hasContentLength () const uint contentLength () const void setContentLength ( int len ) bool hasContentType () const QString contentType () const void setContentType ( const QString & type ) virtual QString toString () const bool isValid () const virtual int majorVersion () const = 0 virtual int minorVersion () const = 0 DESCRIPTION
The QHttpHeader class contains header information for HTTP. In most cases you should use the more specialized derivatives of this class, QHttpResponseHeader and QHttpRequestHeader, rather than directly using QHttpHeader. QHttpHeader provides the HTTP header fields. A HTTP header field consists of a name followed by a colon, a single space, and the field value. (See RFC 1945.) Field names are case-insensitive. A typical header field looks like this: content-type: text/html In the API the header field name is called the "key" and the content is called the "value". You can get and set a header field's value by using its key with value() and setValue(), e.g. header.setValue( "content-type", "text/html" ); QString contentType = header.value( "content-type" ); Some fields are so common that getters and setters are provided for them as a convenient alternative to using value() and setValue(), e.g. contentLength() and contentType(), setContentLength() and setContentType(). Each header key has a single value associated with it. If you set the value for a key which already exists the previous value will be discarded. See also QHttpRequestHeader, QHttpResponseHeader, and Input/Output and Networking. MEMBER FUNCTION DOCUMENTATION
QHttpHeader::QHttpHeader () Constructs an empty HTTP header. QHttpHeader::QHttpHeader ( const QHttpHeader & header ) Constructs a copy of header. QHttpHeader::QHttpHeader ( const QString & str ) Constructs a HTTP header for str. This constructor parses the string str for header fields and adds this information. The str should consist of one or more" " delimited lines; each of these lines should have the format key, colon, space, value. QHttpHeader::~QHttpHeader () [virtual] Destructor. uint QHttpHeader::contentLength () const Returns the value of the special HTTP header field content-length. See also setContentLength() and hasContentLength(). QString QHttpHeader::contentType () const Returns the value of the special HTTP header field content-type. See also setContentType() and hasContentType(). bool QHttpHeader::hasContentLength () const Returns TRUE if the header has an entry for the special HTTP header field content-length; otherwise returns FALSE. See also contentLength() and setContentLength(). bool QHttpHeader::hasContentType () const Returns TRUE if the header has an entry for the the special HTTP header field content-type; otherwise returns FALSE. See also contentType() and setContentType(). bool QHttpHeader::hasKey ( const QString & key ) const Returns TRUE if the HTTP header has an entry with the given key; otherwise returns FALSE. See also value(), setValue(), and keys(). bool QHttpHeader::isValid () const Returns TRUE if the HTTP header is valid; otherwise returns FALSE. A QHttpHeader is invalid if it was created by parsing a malformed string. QStringList QHttpHeader::keys () const Returns a list of the keys in the HTTP header. See also hasKey(). int QHttpHeader::majorVersion () const [pure virtual] Returns the major protocol-version of the HTTP header. Reimplemented in QHttpResponseHeader and QHttpRequestHeader. int QHttpHeader::minorVersion () const [pure virtual] Returns the minor protocol-version of the HTTP header. Reimplemented in QHttpResponseHeader and QHttpRequestHeader. QHttpHeader &; QHttpHeader::operator= ( const QHttpHeader & h ) Assigns h and returns a reference to this http header. void QHttpHeader::removeValue ( const QString & key ) Removes the entry with the key key from the HTTP header. See also value() and setValue(). void QHttpHeader::setContentLength ( int len ) Sets the value of the special HTTP header field content-length to len. See also contentLength() and hasContentLength(). void QHttpHeader::setContentType ( const QString & type ) Sets the value of the special HTTP header field content-type to type. See also contentType() and hasContentType(). Example: network/archivesearch/archivedialog.ui.h. void QHttpHeader::setValue ( const QString & key, const QString & value ) Sets the value of the entry with the key to value. If no entry with key exists, a new entry with the given key and value is created. If an entry with the key already exists, its value is discarded and replaced with the given value. See also value(), hasKey(), and removeValue(). Example: network/archivesearch/archivedialog.ui.h. QString QHttpHeader::toString () const [virtual] Returns a string representation of the HTTP header. The string is suitable for use by the constructor that takes a QString. It consists of lines with the format: key, colon, space, value, " ". QString QHttpHeader::value ( const QString & key ) const Returns the value for the entry with the given key. If no entry has this key, an empty string is returned. See also setValue(), removeValue(), hasKey(), and keys(). SEE ALSO
http://doc.trolltech.com/qhttpheader.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qhttpheader.3qt) and the Qt version (3.3.8). Trolltech AS 2 February 2007 QHttpHeader(3qt)
All times are GMT -4. The time now is 02:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy