09-24-2008
Summing the columns of a file
Hi All,
I have a file like -
num.txt
12, 34, 65, line1
34, 65, 89, line2
43, 65, 77, line3
I want to do two things -
1. Add first three columns of each line and print the line with largest value.
i.e. (12+34+65) for 1st line and so on.
2. Add middle column of each line i.e. (34+65+65) and print the result.
Can this be done without writing a script? I mean just through collection of pipelines commands?
Thanks in advance
-asahlot
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Basically I have to process a text file which has been sorted this way:
John 12
John 13
John 10
John 900
Peter 20
Peter 30
Peter 32
The first column is a name, and the second an arbitrary value, both delimited by a space. How can I sum them up such that it would become:
John 935... (2 Replies)
Discussion started by: Dwee
2 Replies
2. Homework & Coursework Questions
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Hi guys, i'm a new guy here, and it's my first time creating a unix script.
can you guys help me out here? i'd... (3 Replies)
Discussion started by: ramneim
3 Replies
3. Homework & Coursework Questions
1. The problem statement, all variables and given/known data:
Hi guys, i'm a new guy here, and it's my first time creating a unix script.
can you guys help me out here? i'd really appreciate it. :(
Here's my problem:
This is the file i'm using, it has 6 columns, the first three columns are... (12 Replies)
Discussion started by: ramneim
12 Replies
4. Shell Programming and Scripting
a,b,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii
a thru ii are digits and strings....
The awk needed....if coloumn 9 == i (coloumn 9 is string ), output the sum of x's(coloumn 22 ) in all records and sum of y's (coloumn 23 ) in all records in a file (records.txt).... (6 Replies)
Discussion started by: BrownBob
6 Replies
5. UNIX for Dummies Questions & Answers
Can anyone tell me how sum values in each record of a file and append that value to the end? For instance a typical record will be:
FY12,Budget,771100,,,,,,,,,250,-250
I'd like the record to become
FY12,Budget,771100,,,,,,,,,250,-250,0
which can be put into another file.
Thank you. (6 Replies)
Discussion started by: LearningLinux2
6 Replies
6. Shell Programming and Scripting
I have a file with the following format
AAAAA 1.34B 0.76B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.90B 0.00B 0.00B 0.46B 0.00B 0.03B 0.00B ... (4 Replies)
Discussion started by: ncwxpanther
4 Replies
7. UNIX Desktop Questions & Answers
I was just curious about how to sum the total file size of a certain type of file. For instance:
$find . -name "*.aif"
will print out the paths to each .aif file. Instead of printing, how could one sum the total space used by all of the aif files? Thanks!
Please use code tags (3 Replies)
Discussion started by: Alexander4444
3 Replies
8. Shell Programming and Scripting
I'm trying to sum a text file using AWK. Here is an example of the file:
600|3H68| 46
600|3H69| 46
600|3H6F| 290
600|3H6G| 24
600|3HDY| 1
600|3HDY| 3
600|3HE0| 1
600|3HE0| 3
I would like to sum the third field if the first... (7 Replies)
Discussion started by: Drenhead
7 Replies
9. Shell Programming and Scripting
I have an input file that looks like:
ID1 V1 ID2 V2 P1 P2 P3 P4 ..... n no. of columns
1 1 1 1 1.0000 1.0000 1.0000 1.0000
1 1 1 2 0.9999 0.8888 0.7777 0.6666
1 2 1 1 0.8888 0.7777 0.6666 0.5555
1 2 1 2 0.7777 0.6666 0.5555 0.4444
2 1 1 1 0.6666 0.5555 0.4444 0.3333
2 1 1 2 0.5555 0.4444... (4 Replies)
Discussion started by: sdp
4 Replies
10. Shell Programming and Scripting
input:
chr1 1 2 3
chr1 1 2 4
chr1 2 4 5
chr2 3 6 9
chr2 3 6 10
Code:
awk '{a+=$4}END{for (i in a) print i,a}' input
Output:
chr112 7
chr236 19
chr124 5
Desired output:
chr1 1 2 7
chr2 3 6 19
chr1 2 4 5 (1 Reply)
Discussion started by: jacobs.smith
1 Replies
cam(1) General Commands Manual cam(1)
NAME
cam - CPU'S AUDIO MIXER for Linux
SYNOPSIS
cam [-v x,y] [--volume x,y] [-b x,y] [--bass x,y] [-t x,y] [--treble x,y] [-s x,y] [--synth x,y] [-p x,y] [--pcm x,y] [-S x,y]
[--speaker x,y] [-l x,y] [--line x,y] [-m x,y] [--mic x,y] [-c x,y] [--cd x,y] [-M x,y] [--mixer x,y] [-a x,y] [--altpcm x,y] [-r
x,y] [--reclev x,y] [-i x,y] [--igain x,y] [-o x,y] [--ogain x,y] [-l1 x,y] [--line1 x,y] [-l2 x,y] [--line2 x,y] [-l3 x,y] [--line3
x,y] [-3d 1|0] [--3dse 1|0] [-agc 1|0] [--agc 1|0] [-h] [-?] [--help] [-get] [-save] [-getfile filename] [-savefile filename]
xcam
DESCRIPTION
This is an audio mixer for Linux. You have the choice to use it with an interface or at the command line.
OPTIONS
When using the interface you can use the following keys :
LEFT ARROW
decrease the volume of the current device.
RIGHT ARROW
increase the volume of the current device.
UP ARROW
go to previous device.
DOWN ARROW
go to next device.
L locks or unlocks :
unlocked : you can control the left and right channel
separately.
lock : left and right channel are controlled together.
R turn on/off recording mode :
red lamp : recording turned on
green lamp : recording turned off
3 turn on/off 3D Stereo Enhancement (3DSE) device :
when turned on green indicator 3D will be lit at the left side of main volume handle.
A turn on/off microphone Automatic Gain Control :
when turned on green indicator AGC will be lit at the left side of microphone volume handle.
S save the settings of ALL devices in a file ($HOME/.camrc)
G loads the saved settings and restores them.
H shows the help screen.
Q/ESC exits the program and returns to shell.
NOTE: you can use upper or lower case.
When using the command line options the interface is not shown.
The following options are available :
-v, --volume x,y
Set 'volume' to x (left) and y (right)
-b, --bass x,y
Set 'bass' to x (left) and y (right)
-t, --trebble x,y
Set 'treble' to x (left) and y (right)
-s, --synth x,y
Set 'synth' to x (left) and y (right)
-p, --pcm x,y
Set 'pcm' to x (left) and y (right)
-S, --speaker x,y
Set 'speaker' to x (left) and y (right)
-l, --line x,y
Set 'line in' to x (left) and y (right)
-m, --mic x,y
Set 'microphone' to x (left) and y (right)
-c, --cd x,y
Set 'CD in' to x (left) and y (right)
-I, --imix x,y
Set 'mixer' to x (left) and y (right)
-a, --altpcm x,y
Set 'altpcm' to x (left) and y (right)
-r, --reclev x,y
Set 'record level' to x (left) and y (right)
-i, --igain x,y
Set 'input gain' to x (left) and y (right)
-o, --ogain x,y
Set 'output gain' to x (left) and y (right)
-l1, --line1 x,y
Set 'line 1' to x (left) and y (right)
-l2, --line2 x,y
Set 'line 2' to x (left) and y (right)
-l3, --line3 x,y
Set 'line 3' to x (left) and y (right)
-3d, --3dse 1|0
Set 3D Stereo Enhancement to 1 (on) or 0 (off)
-agc, --agc 1|0
Set Automatic Gain Control for microphone to 1 (on) or 0 (off)
-get restore the saved values from $HOME/.camrc
-save save the values to $HOME/.camrc
-getfile filename
restore the saved values from file 'filename'
-savefile filename
save the values to file 'filename'
-h, -?, --help
displays help
NOTE: x and y are in range from 1 to 100. Higher or lower numbers are
ignored.
BUGS
None known as yet. If you find one, please let me know.
AUTHOR
Jan 'TWP' VANDENBERGHE <jvdbergh@uia.ua.ac.be>
cam(1)