Averaging all fields while counting repeated records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Averaging all fields while counting repeated records
# 1  
Old 10-15-2009
Averaging all fields while counting repeated records

Hi every one;

I have a 31500-line text file upon which two following tasks are to be performed:

1: Rearranging the file
2: Taking the average of each column (considering number of zeros) and output the result into a new file

This is the code I've come up with:
Code:
awk '(NR%3150<3150) {print>""NR%175}' infile
while ( j<19 )
awk '{for (i=1;i<=NF;i++) {sum+=$i}} END{d=sort|uniq -c ; print sum/(18-$d)}' $j>>outfile
done

So the first line takes multiple lines in that each following lines output to a different files numbered 1 through 18:
(1,176, 351,526,...)> file1
(2, 177, 352, 527,...)>file2 and so on.
the second awk command takes the average of all fields and append it to the output file.
Here I am also trying to count the number of zeros which does not work.

Any help on this is highly appreciated.
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk for matching fields between files with repeated records

Hello all, I am having trouble with what should be an easy task, but seem to be missing something fundamental. I have two files, with File 1 consisting of a single field of many thousands of records. I also have File 2 with two fields and many thousands of records. My goal is that when $1 of... (2 Replies)
Discussion started by: jvoot
2 Replies

2. UNIX for Beginners Questions & Answers

Matching fields between two files, repeated records

In two previous posts (here) and (here), I received help from forum members comparing multiple fields across two files and selectively printing portions of each as output based upon would-be matches using awk. I had been fairly comfortable populating awk arrays with fields and using awk's special... (3 Replies)
Discussion started by: jvoot
3 Replies

3. Homework & Coursework Questions

Accepting a phrase and counting the number of times that it is repeated in a specific website

1. The problem statement, all variables and given/known data: Develop a shell script that accepts a phrase and counts the number of times that it is repeated in a specific website. Note: Im not sure if it's the whole website, or just a specific page but im guessing its thewhole website. ... (2 Replies)
Discussion started by: Zakerii
2 Replies

4. Shell Programming and Scripting

Counting the records based on condition

Hi Unix team, I have a file with 30 columns with tab delimited. I need to count the records based on column 18 & 21 data. So I cut the data from the file using awk -F"\t" '{print $18,$21}' foo.txt Following is the output: USED SEDAN USED SUV NEW SUV USED Truck USED Truck USED... (6 Replies)
Discussion started by: karumudi7
6 Replies

5. Shell Programming and Scripting

Counting Fields with awk

ok, so a user can specify options as is shown below: ExA: cpu.pl!23!25!-allow or ExB: cpu.pl!23!25!-block!all options are delimited by the exclamation mark. now, in example A, there are 4 options provided by the user. in example B, there are 5 options provided by the user. ... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. Emergency UNIX and Linux Support

[Solved] Extract records based on a repeated column value

Hi guys, I need help in making a command to find some data. I have multiple files in which multiple records are present.. Each record is separated with a carriage return and in each record there are multiple fields with each field separated by "|" what i want is that I want to extract... (1 Reply)
Discussion started by: m_usmanayub
1 Replies

7. Shell Programming and Scripting

Help in counting the no of repeated words with count in a file

Hi Pls help in solving my doubt.Iam having file like below file1.txt priya jenny jenny priya raj radhika priya bharti bharti Output required: I need a output like count of repeated words with name for ex: priya 3 jenny 2 (4 Replies)
Discussion started by: bha148
4 Replies

8. Shell Programming and Scripting

Help me in counting records from file

Hi, Please help me in counting the below records(1st field) from samplefile: Expected output: Count Descr ------------------------------------------- 7 Mean manager 14 ... (7 Replies)
Discussion started by: prashant43
7 Replies

9. Shell Programming and Scripting

Counting records with AWK

I've been working with an awk script and I'm wondeing id it's possible to count records in a file which DO NOT contain, in this instance fields 12 and 13. With the one script I am wanting to display the count for the records WITH fields 12 and 13 and a seperate count of records WITHOUT fields... (2 Replies)
Discussion started by: Glyn_Mo
2 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question
INTERFACE-ORDER(5)						    resolvconf							INTERFACE-ORDER(5)

NAME
interface-order - resolvconf configuration file DESCRIPTION
The file /etc/resolvconf/interface-order is used to control the order in which resolvconf nameserver information records are processed by those resolvconf update scripts that consult this file. (The name of the file is apt because a resolvconf nameserver information record is named after the interface with which it is associated.) The file contains a sequence of shell glob patterns, one per line. The position of a record in the order is the point at which its name first matches a pattern. Patterns may not contain whitespace, slashes or initial dots or tildes. Blank lines and lines beginning with a '#' are ignored. Resolvconf update scripts in /etc/resolvconf/update.d/ that consult this file include the current default versions of dnsmasq, pdnsd and libc. (Actually they don't read the file directly; they call the utility program /lib/resolvconf/list-records which lists records in the specified order and omits the names of empty records.) EXAMPLE
# /etc/resolvconf/interface-order # Use nameservers on the loopback interface first. lo* # Next use records for Ethernet interfaces eth* # Next use records for Wi-Fi interfaces wlan* # Next use records for PPP interfaces ppp* # Last use other interfaces * AUTHOR
Resolvconf was written by Thomas Hood <jdthood@gmail.com>. COPYRIGHT
Copyright (C) 2004, 2011 Thomas Hood This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
resolvconf(8) resolvconf 18 May 2011 INTERFACE-ORDER(5)