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
TTYACTION(5)						      BSD File Formats Manual						      TTYACTION(5)

NAME
ttyaction -- ttyaction file format DESCRIPTION
The ttyaction file specifies site-specific commands to run when a login session begins and ends. The ttyaction file contains a list of new- line separated records, where each record has the following three fields: ttyname Name of the tty line(s) on which this line should apply. The name is relative to the /dev directory, similar to how such devices are named in the /etc/ttys file. action Name of the action for which this line should apply. The action names currently defined are "login", "getty", "telnetd" and "rlogind" which indicate which program is processing this file. (Note that "login" begins a login session, while the other three are run after a login session ends.) command What command to run if this record matches. The first two fields are delimited with blanks or tabs, and the command field is all text to the end of the line. Either or both of first two fields may contain wildcard match patterns as implemented by the fnmatch() library function. All command strings are executed by passing them to /bin/sh -c running as "root," with an environment containing: TTY=ttyname ACT=action USER=username PATH=_PATH_STDPATH These variables may be used directly in the shell command part of the record for simple tasks such as changing the ownership of related devices. For example: console * chown ${USER}:tty /dev/mouse will chown the mouse appropriately when the console owner changes. EXAMPLES
Here are some more example records: tty0 login /somewhere/tty_setup ${TTY} tty0 getty /somewhere/tty_clean ${TTY} * * /somewhere/ttyfrob ${TTY} ${ACT} SEE ALSO
fnmatch(3), ttyaction(3) HISTORY
The ideas for the /etc/ttyaction file were inspired by the /etc/fbtab file under SunOS. BSD
August 24, 1996 BSD