Sponsored Content
Full Discussion: Sum in file based column
Top Forums UNIX for Beginners Questions & Answers Sum in file based column Post 303039374 by vgersh99 on Wednesday 2nd of October 2019 01:39:10 PM
Old 10-02-2019
Quote:
Originally Posted by arunkumar_mca
Thanks . When I tried to print the description using the below command I am getting only one description not sure what I am doing wrong
Code:
awk -F'[;]' '{ t[$1]+=$3 } END { for (i in t) print i,$2, t[i] }'  my file

INPUT
10264;ATE;12
10265;SES;11
10266;AUT;50
10264;ATE;10
10265;SES;13
10266;AUT;89
10264;ATE;1
10265;SES;15
10266;AUT;78


OUTPUT
10266 AUT 217
10264 AUT 23
10265 AUT 39

Expected
10266 AUT 217
10264 ATE 23
10265 SES 39

Also if I have the number as 1009090992.1111 the my result is coming as 1.00909e+09 how to get that as a whole number
Code:
awk -F'[;]' '{ t[$1 OFS $2]+=$3 } END { for (i in t) print i, t[i] }'  myFile

For the 'Also' part... please post sample representative input.
This User Gave Thanks to vgersh99 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I sum one column based on another column?

Hi, I am new to this forum and new to awk. I have a file that contains 2 columns. Heres an example of what it looks like: 10 + 20 + 40 + 50 - 70 - So the file is tab-delimited. What I want to do is add 10 to column 1 whenever column 2 is + and substract 10 from column 1... (1 Reply)
Discussion started by: phil_heath
1 Replies

2. Shell Programming and Scripting

sum multiple columns based on column value

i have a file - it will be in sorted order on column 1 abc 0 1 abc 2 3 abc 3 5 def 1 7 def 0 1 -------- i'd like (awk maybe?) to get the results (any ideas)??? abc 5 9 def 1 8 (2 Replies)
Discussion started by: jjoe
2 Replies

3. Shell Programming and Scripting

Sum a column value based on multiple keys

Hi, I have below as i/p file: 5ABC 36488989 K 000010000ASB BYTRES 5PQR 45757754 K 000200005KPC HGTRET 5ABC 36488989 K 000045000ASB HGTRET 5GTH 36488989 K 000200200ASB BYTRES 5FTU ... (2 Replies)
Discussion started by: nirnkv
2 Replies

4. Shell Programming and Scripting

Sum Of Column Based On Column Condition

I have a following inputfile MT,AP,CDM,TTML,MUM,GS,SUCC,3 MT,AP,CDM,TTSL,AP,GS,FAIL,9 MT,AP,CDM,RCom,MAH,GS,SUCC,3 MT,AP,CDM,RTL,HP,GS,SUCC,1 MT,AP,CDM,Uni,UPE,GS,SUCC,2 MT,AP,CDM,Uni,MUM,GS,SUCC,2 TTSL,AP,GS,MT,MAH,CDM,SUCC,20 TTML,AP,GS,MT,MAH,CDM,FAIL,10... (2 Replies)
Discussion started by: siramitsharma
2 Replies

5. UNIX for Dummies Questions & Answers

Sum based on column 1

i have file input aaa ccc,45567,rterw,1 bbb dcs,564543,hjghgh,1 aaa ccc,454,rterw,6 i want to sum based on column 1 expected output aaa ccc,7 bbb dcs,1 (4 Replies)
Discussion started by: radius
4 Replies

6. UNIX for Dummies Questions & Answers

Sum based on certain column

I have file 1 1/1/2013 A 553.0763397 96 16582 X1 X3 X5 X7 X9 1/1/2013 B 600.8333588 195 11992 X2 X3 X6 X7 X9 1/1/2013 B 459.8333588 195 11992 X1 X3 X6 X7 X9 1/2/2013 A 844.2973022 306 19555 X1 ... (12 Replies)
Discussion started by: radius
12 Replies

7. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

8. UNIX for Dummies Questions & Answers

Sum third column in a file when 1 and 2 repeat

Hello, Below is a portion of a file I am working on: 2:15 3001 120 2:15 3001 26.25 2:15 3002 12.5 2:15 3002 15 9:45 3001 45 9:45 3001 45 9:45 3002 105 9:45 3005 180 9:45 3005 123.75 9:45 3005 15 I am trying to get the sum of column 3 for all repeated values of columns 1 and 2 (The... (6 Replies)
Discussion started by: c@rlos
6 Replies

9. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

10. Shell Programming and Scripting

Sum of a column as new column based on header in a script

Hello, I am trying to store sum of a column as a new column inside a file but have to find the column names dynamically I/p c1,c2,c3,c4,c5 10,20,30,40,50 20,30,40,50,60 If i want to find sum only column c1, c3 and output it as c6,c7 O/p c1,c2,c3,c4,c5,c6,c7 10,20,30,40,50,30,70... (6 Replies)
Discussion started by: mkathi
6 Replies
SG_SES(8)							     SG3_UTILS								 SG_SES(8)

NAME
sg_ses - send controls and fetch status from a SCSI Enclosure Services (SES) device SYNOPSIS
sg_ses [--byte1=B1] [--control] [--data=H,H...] [--filter] [--help] [--hex] [--inner-hex] [--list] [--page=PG] [--raw] [--status] [--ver- bose] [--version] DEVICE DESCRIPTION
Send controls to a SES device (via a SCSI SEND DIAGNOSTIC command) or fetches status (via a SCSI RECEIVE DIAGNOSTIC RESULTS command). The DEVICE should be a SES device which may be a dedicated enclosure services processor (INQUIRY peripheral device type 0xd) or attached to another type of SCSI device (e.g. a disk) in which case the EncServ bit set in its INQUIRY response. If no options are given (only the DEVICE argument) then all diagnostic pages supported by the device (including SES pages) are listed. OPTIONS
Arguments to long options are mandatory for short options as well. The options are arranged in alphabetical order based on the long option name. -b, --byte1=B1 some control pages need byte 1 (i.e. the second byte) of the cdb set. Only required in rare cases when the --control option is also set. Default is 0; B1 is in decimal unless it is prefixed by '0x' or '0X' (or has a trailing 'h' or 'H'). -c, --control will send control information to the DEVICE via a SCSI SEND DIAGNOSTIC command. Cannot give both this option and --status. The Enclosure control, String Out, Threshold Out, Array control (obsolete in SES-2) and Subenclosure String Out diagnostic pages can be set currently. -d, --data=H,H... permits a string of comma separated (ASCII) hex digits to be specified (limit 512). This allows the parameters to a control diagnos- tic page to be specified. The string given should not include the first 4 bytes (i.e. page code and length). See next entry for using stdin. -d, --data=- reads a data string from stdin. Spaces, tabs and line feeds additionally are permitted as separators. -f, --filter cuts down on the amount of output from the enclosure status diagnostic page. When this option is given, any line which has all its binary flags cleared (i.e. 0) is filtered out (i.e. ignored). If a line has some other value on it (e.g. a temperature) then it is output. -h, --help output the usage message then exit. -H, --hex output the response in hexadecimal. -i, --inner-hex the outer levels of a status diagnostic page are decoded and printed out but the innermost level (e.g. the element status descrip- tor) is output in hex. Implemented for the more complex diagnostic pages. -l, --list list all known diagnostic page names and SES elements. DEVICE is ignored and utility exits. -p, --page=PG where PG is a page code. Assumed to be in decimal unless prefixed by 0x for hex. Valid range is 0 to 255 (0x0 to 0xff) inclusive. Default is page_code 0 (i.e. "Supported diagnostic pages"). -r, --raw outputs the chosen status page in (ASCII) hex in a format suitable for a later invocation using the --data= option. A status diag- nostic page less its first 4 bytes (page code and length) is output. When used twice (e.g. -rr) outputs full diagnostic page in binary to stdout. -s, --status will fetch status diagnostic page from the DEVICE via a SCSI RECEIVE DIAGNOSTIC RESULTS command. If this option is not given and --control is not given then --status is assumed. -v, --verbose increase the level of verbosity, (i.e. debug output). -V, --version print the version string and then exit. NOTES
Currently all status pages, control pages and element types defined in SES-2 revision 17 (14th May 2007) are decoded. This utility can be used to fetch arbitrary (i.e. non SES) diagnostic pages (using the SCSI READ DIAGNOSTIC command). To this end the --page=PG and --hex options would be appropriate. Arbitrary diagnostic pages can be sent to a device with the sg_senddiag utility. There is a related command set called SAF-TE (SCSI attached fault-tolerant enclosure) for enclosure (including RAID) status and control. SCSI devices that support SAF-TE report "Processor" peripheral device type (0x3) in their INQUIRY response. See the sg_safte utility in this package or safte-monitor on the internet. EXAMPLES
To view the supported pages: sg_ses /dev/sda To view the configuration page: sg_ses --page=1 /dev/sda To view the status page: sg_ses --page=2 /dev/sda Changing a temperature threshold is possible, if a little awkward. The current thresholds can be shown with: sg_ses --page=5 /dev/sda The threshold to be changed can be chosen. Then output the threshold page in hex (suitable for editing) with: sg_ses --page=5 --raw /dev/sda > t Then with the aid of the SES-2 document (in revision 9: section 6.1.8) use your favourite editor to change t. The change can be sent to the device with: sg_ses --control --page=5 --data=- /dev/sda < t If the above is successful, the threshold should have been changed. To check try: sg_ses --page=5 /dev/sda again. EXIT STATUS
The exit status of sg_ses is 0 when it is successful. Otherwise see the sg3_utils(8) man page. AUTHORS
Written by Douglas Gilbert. REPORTING BUGS
Report bugs to <dgilbert at interlog dot com>. COPYRIGHT
Copyright (C) 2004-2007 Douglas Gilbert This software is distributed under a FreeBSD license. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR- POSE. SEE ALSO
sg_inq, sg_safte, sg_senddiag (in sg3_utils package); safte-monitor (internet) sg3_utils-1.26 March 2008 SG_SES(8)
All times are GMT -4. The time now is 12:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy