awk math and csv output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk math and csv output
# 1  
Old 10-26-2012
awk math and csv output

Hi I have this list
Code:
 
592;1;Z:\WB\DOCS;/FS3_100G/FILER112/BU/MPS/DOCS;;;;\\FILER112\BUMPS-DOCS\;580,116,544,878 Bytes;656,561 ;77,560 
592;2;Z:\WB\FOCUS;/FS3_100G/FILER112/BU/MPS/FOCUS;;;;\\FILER112\BUMPS-FOCUS\;172,430 Bytes;6 ;0 
896;3;Z:\WB\FUNDONFUND;/FS3_100G/FILER112/BU/MPS/FUNDONFUND;;;;\\FILER112\BUMPS-FOFUND\;0 Bytes;0 ;0 
592;4;Z:\WB\MONARCH;/FS3_100G/FILER112/BU/MPS/MONARCH;;;;\\FILER112\BUMPS-MON\;14,531,579 Bytes;137 ;3 
931;5;S:\X\DIST\DV;/FS7_100G/FILER104/BU-D/DIST/DV;;;;\\FILER104\BUDIST-DV\;452,928,819 Bytes;10 ;2

Delimiter semicolon ;
Field #9 is the folder size

I would like to have the same list instead of bytes converted to GB

I tried to run
Code:
 
awk -F ";" '{print $9/1024/1024/1024}' file

but it does not work.
Help is appreciated, it could also be in perl.
# 2  
Old 10-26-2012
First remove all the strings and , from the $9.

use

Code:
awk -F ";" '{ gsub("[A-z]","",$9);gsub(",","",$9); print $9/(1024*1024*1024)}' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 10-26-2012
Code:
awk -F\; '{gsub(/,/,"",$9);$9=($9/1024/1024/1024) " GB"}1' CONVFMT='%.6f' OFS=\; file

This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 10-26-2012
Try like..
Code:
awk -F ";" '{print $9+0/(1024*1024*1024)}' test.txt

# 5  
Old 10-26-2012
Quote:
Originally Posted by bmk
Try like..
Code:
awk -F ";" '{print $9+0/(1024*1024*1024)}' test.txt

That will not work. 9th field has commas too. That will make awk treat $9 as a number upto the first comma.
# 6  
Old 10-26-2012
Sorry ,i didn't notice..
# 7  
Old 10-29-2012
Quote:
Originally Posted by elixir_sinari
Code:
awk -F\; '{gsub(/,/,"",$9);$9=($9/1024/1024/1024) " GB"}1' CONVFMT='%.6f' OFS=\; file

Thank you this is worked perfectly but I have a question.
Is it possible to keep the $9 field with the size in bytes, and to add a new field in GB?

I tried this and it works, but is there a simpler way to do it?
Windows awk
Code:
awk -F ";" "{ gsub(\"[A-z]\",\"\",$9);gsub(\",\",\"\",$9); print $1\";\"$2\";\"$3\";\"$4\";\"$9\"Bytes\"\";\" $9/(1024*1024*1024)\" GB\"}" CONVFMT="%.6f" file


Code:
 
awk -F ";" '{ gsub("[A-z]","",$9);gsub(",","",$9); print $1";"$2";"$3";"$4";"$9"Bytes"";" $9/(1024*1024*1024)" GB"}' CONVFMT='%.6f' s.final.csv>s.final.gb.csv

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 and sed script to create one output CSV file

Hi All , I would require your help to generate one output file after post processing of one CSV file as stated below This file is just a small cut from a big file . Big file is having 20000 lines PATTERN,pat0,pat1,pat2,pat3,pat4,pat5,pat6,pat7,pat8,pat9... (2 Replies)
Discussion started by: kshitij
2 Replies

2. Shell Programming and Scripting

How to parse this file using awk and output in CSV format?

My source file looks like this: Cust-Number = "101" Cust-Name="Joe" Cust-Town="London" Cust-hobby="tennis" Cust-purchase="200" Cust-Number = "102" Cust-Name="Mary" Cust-Town="Newyork" Cust-hobby="reading" Cust-purchase="125" Now I want to parse this file (leaving out hobby) and... (10 Replies)
Discussion started by: Balav
10 Replies

3. Shell Programming and Scripting

Help! Printing out CSV output from awk Pattern Match

Hi, I need to search for a word using Awk and print out the line the word is in and every line after the search phrase until I hit this #------------. Then I need to send it to a csv file. So basically the input file format is like this:... (1 Reply)
Discussion started by: An0mander
1 Replies

4. Shell Programming and Scripting

Math count %memory using awk

Hi expert, i have log this: Memory: 74410384 Memory: 75831176 Memory: 77961232 Memory: 77074656 Memory: 76086160 Memory: 77128592 Memory: 78045384 Memory: 76696040 Memory: 72401176 Memory: 72520016 Memory: 72137016 Memory: 73175832 Memory: 73034528 Memory: 71770736 Memory:... (4 Replies)
Discussion started by: justbow
4 Replies

5. Shell Programming and Scripting

Count math using awk

Hi expert, I have log : TOTAL-TIME : 2125264636 DATA-BYTES-DOWN : 3766111307032 DATA-BYTES-UP : 455032157567 DL = (3766111307032/2125264636)/1024 = 1.73 UL = (455032157567/2125264636)/1024 = 0.21 I want the result : TOTAL = 1.94 ... (4 Replies)
Discussion started by: justbow
4 Replies

6. Shell Programming and Scripting

awk --> math-operation in a array

Hi main object is categorize the difference of data-values (TLUFT02B - TLUFT12B). herefor i read out data-files which are named acording to the timeformat yyyymmddhhmm. WR030B 266.48 Grad 0 WR050B 271.46 Grad 0 WR120B 268.11 Grad 0 WV030B 2.51 m/s ... (6 Replies)
Discussion started by: IMPe
6 Replies

7. Shell Programming and Scripting

Need help with AWK math

I am trying to do some math, so that I can compare the average of six numbers to a variable. Here is what it looks like (note that when I divide really big numbers, it isn't a real number): $ tail -n 6 named.stats | awk -F\, '{print$1}' 1141804 1140566 1139429 1134210 1084682 895045... (3 Replies)
Discussion started by: brianjb
3 Replies

8. Shell Programming and Scripting

awk math operation on two files

Hi, I need your help. I've got two files and i need to add 2nd line after occurrence of "Group No X" from data2.txt to 3rd line (after occurrence of "Group No X") from data1.txt. There is the same number of "Groups" in both files and the numbers of groups have the same pattern. data1.txt Group... (2 Replies)
Discussion started by: killerbee
2 Replies

9. UNIX for Dummies Questions & Answers

awk logic and math help

Hi, My file has 2 fields and millions of lines. variableStep chrom=Uextra span=25 201 0.5952 226 0.330693 251 0.121004 276 0.0736858 301 0.0646982 326 0.0736858 401 0.2952 426 0.230693 451 0.221004 476 0.2736858 Each field either has a... (6 Replies)
Discussion started by: wyarosh
6 Replies

10. UNIX for Dummies Questions & Answers

Math with wordcount output

Hi I know very little about unix. I have a unix code (which I'm running in geektools) which gives me the word count of a pages document. However, the pages document innately contains 522 words of superfluous "Ipsem Lorem..." text which are included in the count. How would I go about... (4 Replies)
Discussion started by: eunoia7
4 Replies
Login or Register to Ask a Question