Sponsored Content
Top Forums Shell Programming and Scripting How to add lines of a file and average them Post 302604750 by agama on Monday 5th of March 2012 11:40:25 PM
Old 03-06-2012
Quote:
Originally Posted by AxlVanDamme
Thanks for the reply. I'd like to keep them in a file and not in the shell though. Is there a way to do that?
They'd be in a file. The script, or the awk, read's the file, sums the numbers and presents the average. The 'input-file' or 'input-file-name' in the samples would be the name of your file that contains the numbers.
This User Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add lines into file

Hi, i have a file like: 00:00 8 00:01 2 00:04 5 00:07 10 . . . and i need to add the other minutes with value 0 and have a file like: 00:00 8 00:01 2 00:02 0 00:03 0 00:04 5 00:05 0 00:06 ... (13 Replies)
Discussion started by: Lestat
13 Replies

2. Shell Programming and Scripting

add lines in file with perl

How to search string like: a and replace to a a a : : a in a file with perl? Thanks, Grace (6 Replies)
Discussion started by: jinsh
6 Replies

3. Shell Programming and Scripting

add few lines to a file in unix

Hi, I have an xml file <Disp x=y a=b Disp/> <Disp q=1 w=2 Disp/> ..... I want to add a new set in between like this for a set of 100 files. <Disp x=y a=b Disp/> <Disp k=1 z=2 Disp/> <Disp q=1 w=2 (7 Replies)
Discussion started by: naga_5star
7 Replies

4. Shell Programming and Scripting

print running field average for a set of lines

Hi everyone, I have a program that generates logs that contains sections like this: IMAGE INPUT 81 0 0.995 2449470 0 1726 368 1 0.0635 0.3291 82 0 1.001 2448013 0 1666 365 1 0.0649 0.3235 83 0 1.009 2444822 0 1697 371 1 ... (3 Replies)
Discussion started by: euval
3 Replies

5. Shell Programming and Scripting

Extract some lines from one file and add those lines to current file

hi, i have two files. file1.sh echo "unix" echo "linux" file2.sh echo "unix linux forums" now the output i need is $./file2.sh unix linux forums (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

6. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

7. Shell Programming and Scripting

Add 3 new lines for every line in a file

I have a file that I need to add 3 new lines of text for every line in the file - when I attempt the sed scripting below I keep getting 'command garbled' errors. Any suggestions would be greatly appreciated #!/bin/ksh list=`cat /export/home/list` for i in $list do sed ' a \... (7 Replies)
Discussion started by: bjdamon
7 Replies

8. Shell Programming and Scripting

Combine identical lines and average the one variable field

I have the following file 299899 chrX_299716_300082 196 78.2903 299991 chrX_299982_300000 18.2538 Tajd:0.745591 FayWu:-0.245701 T2:1.45 299899 chrX_299716_300082 196 78.2903 299991 chrX_299982_300000 18.2538 Tajd:0.745591 FayWu:-0.245701 T2:0.283 311027 chrX_310892_311162 300 91.6452... (2 Replies)
Discussion started by: jfern
2 Replies

9. Shell Programming and Scripting

Get the average of lines with the same first 4 letters

How to sum up and print into the next line the total SUM. ]$ cat hhhh aaa1a 1 aaa1g 2 aaa1f 3 baa4f 3 baa4d 4 baa4s 4 cddg1 3 cddg3 4 cddfg 1 $ cat hhhh|awk ' {sum+=$2} END {print sum}' 25 Desire output: aaa1a 1 (13 Replies)
Discussion started by: kenshinhimura
13 Replies

10. UNIX for Beginners Questions & Answers

awk to average matching lines in file

The awk below executes and is close (producing the first 4 columns in desired). However, when I add the sum of $7, I get nothing returned. Basically, I am trying to combine all the matching $4 in f1 and output them with the average of $7 in each match. Thank you :). f1 ... (2 Replies)
Discussion started by: cmccabe
2 Replies
pnmconvol(1)						      General Commands Manual						      pnmconvol(1)

NAME
pnmconvol - general MxN convolution on a portable anymap SYNOPSIS
pnmconvol convolutionfile [pnmfile] DESCRIPTION
Reads two portable anymaps as input. Convolves the second using the first, and writes a portable anymap as output. Convolution means replacing each pixel with a weighted average of the nearby pixels. The weights and the area to average are determined by the convolution matrix. The unsigned numbers in the convolution file are offset by -maxval/2 to make signed numbers, and then normalized, so the actual values in the convolution file are only relative. Here is a sample convolution file; it does a simple average of the nine immediate neighbors, resulting in a smoothed image: P2 3 3 18 10 10 10 10 10 10 10 10 10 To see how this works, do the above-mentioned offset: 10 - 18/2 gives 1. The possible range of values is from 0 to 18, and after the off- set that's -9 to 9. The normalization step makes the range -1 to 1, and the values get scaled correspondingly so they become 1/9 - exactly what you want. The equivalent matrix for 5x5 smoothing would have maxval 50 and be filled with 26. The convolution file will usually be a graymap, so that the same convolution gets applied to each color component. However, if you want to use a pixmap and do a different convolution to different colors, you can certainly do that. At the edges of the convolved image, where the convolution matrix would extend over the edge of the image, pnmconvol just copies the input pixels directly to the output. SEE ALSO
pnmsmooth(1), pnm(5) AUTHORS
Copyright (C) 1989, 1991 by Jef Poskanzer. Modified 26 November 1994 by Mike Burns, burns@chem.psu.edu 26 November 1994 pnmconvol(1)
All times are GMT -4. The time now is 08:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy