Sponsored Content
Top Forums Shell Programming and Scripting Question about File Processing Post 302634177 by inditopgun on Thursday 3rd of May 2012 02:29:36 AM
Old 05-03-2012
Question about File Processing

I have a file with the format

Code:
CKF,23G
ckf,234M
CKF,2356K
DFK,4589M
DFK,343K
dfk,3434M
DFK,34G
DFK,34343M,
DFK,3476G
FGK,34k
KLK,43G
KLK,3G

I would like to group by the 3-letter code in the beginning of the file and sum up the second column in giga bytes and output a file like the following :

Code:
CKF,<sum_total_of_all_rows_in_gigabytes>G
DFK,<sum_total_of_all_rows_in_gigabytes>G
FGK,<sum_total_of_all_rows_in_gigabytes>G
KLK,<sum_total_of_all_rows_in_gigabytes>G

To calculate in giga bytes, the size mentioned on each row needs to be handled as follows :
if suffix is G, then do nothing, simply add to running_total
if suffix is M or m, then divide by 1024 and add to running_total
if suffix is K o k then divide by (1024*1024) and add to running_total

Last edited by Scrutinizer; 05-03-2012 at 03:43 AM.. Reason: code tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies

2. Shell Programming and Scripting

Checking for a control file before processing a data file

Hi All, I am very new to Shell scripting... I got a requirement. I will have few text files(data files) in a particular directory. they will be with .txt extension. With same name, but with a different extension control files also will be there. For example, Sample_20081001.txt is the data... (4 Replies)
Discussion started by: purna.cherukuri
4 Replies

3. Shell Programming and Scripting

how to change the current file processing to some other random file in awk ?

Hello, say suppose i am processing an file emp.dat the field of which are deptno empno empname etc now say suppose i want to change the file to emp.lst then how can i do it? Here i what i attempted but in vain BEGIN{ system("sort emp.dat > emp.lst") FILENAME="emp.lst" } { print... (2 Replies)
Discussion started by: salman4u
2 Replies

4. UNIX for Dummies Questions & Answers

a dummy question on data processing

Hi, everyone, I have a matrix, let's say: 1 2 3 4 5 6 ... 4 5 6 7 8 9 ... 7 8 9 1 2 3 ... 3 4 5 6 7 8 ... ......... (nxm matrix) Is there a simple command that can take certain specific rows out of the matrix? e.g., I want to take row 2 (4 5 6 7 8 9 ...) and row 4 (3 4 5 6 7 8... (2 Replies)
Discussion started by: kaixinsjtu
2 Replies

5. UNIX for Dummies Questions & Answers

Basic file processing question

I have a csv file with 3 columns. Column 1 is a date "mm/dd/yyyy", column 2 is a dollar amount (e.g. "100.00") & column 3 in a description of where the transaction took place (e.g. "CHECK CRD PURCHASE 10/07 ACME INC USA") so... "10/01/2009","100.00", "CHECK CRD PURCHASE 10/07 ACME INC USA" I... (1 Reply)
Discussion started by: watingo
1 Replies

6. Shell Programming and Scripting

How to make parallel processing rather than serial processing ??

Hello everybody, I have a little problem with one of my program. I made a plugin for collectd (a stats collector for my servers) but I have a problem to make it run in parallel. My program gathers stats from logs, so it needs to run in background waiting for any new lines added in the log... (0 Replies)
Discussion started by: Samb95
0 Replies

7. Shell Programming and Scripting

Recursive file processing from a path and printing output in a file

Hi All, The script below read the path and searches for the directories/subdirectories and for the files. If files are found in the sub directories then read the content of the all files and put the content in csv(comma delimted) format and the call the write to xml function to write the std... (1 Reply)
Discussion started by: Optimus81
1 Replies

8. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

9. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies
HUMANIZE_NUMBER(3)					   BSD Library Functions Manual 					HUMANIZE_NUMBER(3)

NAME
dehumanize_number, humanize_number -- format a number into a human readable form and viceversa LIBRARY
Utility functions from BSD systems (libbsd, -lbsd) SYNOPSIS
#include <bsd/stdlib.h> int dehumanize_number(const char *str, int64_t *result); int humanize_number(char *buf, size_t len, int64_t number, const char *suffix, int scale, int flags); DESCRIPTION
The humanize_number() function formats the signed 64 bit quantity given in number into buffer. A space and then suffix is appended to the end. buffer must be at least len bytes long. If the formatted number (including suffix) would be too long to fit into buffer, then divide number by 1024 until it will. In this case, prefix suffix with the appropriate SI designator. The prefixes are: Prefix Description Multiplier k kilo 1024 M mega 1048576 G giga 1073741824 T tera 1099511627776 P peta 1125899906842624 E exa 1152921504606846976 len must be at least 4 plus the length of suffix, in order to ensure a useful result is generated into buffer. To use a specific prefix, specify this as scale (Multiplier = 1024 ^ scale). This can not be combined with any of the scale flags below. The following flags may be passed in scale: HN_AUTOSCALE Format the buffer using the lowest multiplier possible. HN_GETSCALE Return the prefix index number (the number of times number must be divided to fit) instead of formatting it to the buf- fer. The following flags may be passed in flags: HN_DECIMAL If the final result is less than 10, display it using one digit. HN_NOSPACE Do not put a space between number and the prefix. HN_B Use 'B' (bytes) as prefix if the original result does not have a prefix. HN_DIVISOR_1000 Divide number with 1000 instead of 1024. The dehumanize_number() function parses the string representing an integral value given in str and stores the numerical value in the integer pointed to by result. The provided string may hold one of the suffixes, which will be interpreted and used to scale up its accompanying numerical value. RETURN VALUES
humanize_number() returns the number of characters stored in buffer (excluding the terminating NUL) upon success, or -1 upon failure. If HN_GETSCALE is specified, the prefix index number will be returned instead. dehumanize_number() returns 0 if the string was parsed correctly. A -1 is returned to indicate failure and an error code is stored in errno. ERRORS
dehumanize_number() will fail and no number will be stored in result if: [EINVAL] The string in str was empty or carried an unknown suffix. [ERANGE] The string in str represented a number that does not fit in result. SEE ALSO
humanize_number(9) HISTORY
humanize_number() first appeared in NetBSD 2.0. dehumanize_number() first appeared in NetBSD 5.0. BSD
February 9, 2008 BSD
All times are GMT -4. The time now is 03:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy