Sponsored Content
Full Discussion: .csv file manipulation
Top Forums Shell Programming and Scripting .csv file manipulation Post 302907473 by kekanap on Saturday 28th of June 2014 01:03:55 PM
Old 06-28-2014
Hallo Team,

This is how the file looks like before i run the command that you suggested i run:

Code:
[mind@util1-pkl MHG_201406]$ cat Pax.csv
AccountCode,AccountName,UniqueCallId,FromNumber,ToNumber,DestinationDescription,CallType,CallDate,CallTime,CallDuration,CallDurationSec,Cost,TelkomAsIf
563416,MHG - Braamfontein,3260306859:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,20-JUN-2014,17:03:56,00:00:05,5,.0125,0.5
563416,MHG - Braamfontein,3275326523:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,23-JUN-2014,14:19:07,00:00:20,20,.05,0.5
563416,MHG - Braamfontein,3280178113:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,24-JUN-2014,08:06:23,00:00:06,6,.015,0.5
563416,MHG - Braamfontein,3305018045:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,26-JUN-2014,10:32:13,00:00:06,6,.015,0.5
563416,MHG - Braamfontein,3305020549:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,26-JUN-2014,10:32:22,00:00:04,4,.01,0.5
563416,MHG - Braamfontein,3064064999:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,28-MAY-2014,12:05:07,00:00:06,6,.015,0.5
563416,MHG - Braamfontein,3071554761:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,29-MAY-2014,09:12:05,00:00:20,20,.05,0.5
563416,MHG - Braamfontein,3076236709:0A,0860101280,0113812027,Johannesburg area,VoIS Contact Sharecall Overflow,29-MAY-2014,14:07:51,00:00:01,1,.0025,0.5
563416,MHG - Braamfontein,3082567491:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,30-MAY-2014,10:00:47,00:00:07,7,.0175,0.5
661178,MHG - Cape Town,3257924103:0A,0860102472,0214804774,Cape Town area,VoIS Contact Sharecall Overflow,20-JUN-2014,14:07:13,00:00:16,16,.04,0.5
661178,MHG - Cape Town,3059920319:1830,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,28-MAY-2014,10:52:34,00:10:52,652,1.8473,2.7167
661178,MHG - Cape Town,3059920319:1890,0214804511,0860104111,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,28-MAY-2014,10:57:09,00:10:01,601,1.7028,2.5042
661178,MHG - Cape Town,3070357179:360,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,29-MAY-2014,08:46:20,00:20:39,1239,3.5105,5.1625
661178,MHG - Cape Town,3070357179:824,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,29-MAY-2014,09:35:03,00:18:44,1124,3.1847,4.6833
661178,MHG - Cape Town,3070357179:1103,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,29-MAY-2014,10:03:07,00:00:48,48,.136,0.2
661178,MHG - Cape Town,3070357179:4351,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,29-MAY-2014,14:17:10,00:07:22,442,1.2523,1.8417
661178,MHG - Cape Town,3080634155:1403,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,30-MAY-2014,10:28:53,00:04:43,283,.8018,1.1792
661178,MHG - Cape Town,3080634155:3172,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,30-MAY-2014,13:01:29,00:06:22,382,1.0823,1.5917
661178,MHG - Cape Town,3080634155:3622,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,30-MAY-2014,13:38:33,00:03:08,188,.5327,0.7833
661178,MHG - Cape Town,3080634155:3648,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,30-MAY-2014,13:41:42,00:19:29,1169,3.3122,4.8708
[mind@util1-pkl MHG_201406]$ awk -F, -v OFS="," '
> $7 ~ /VoIS Community Sharecall/ { $12=($10*0.19)/60 }
> $7 ~ /VoIS Contact Sharecall Overflow/ { $12=($10*0.4)/60 }
> { $13=($13*0.5)/60 }
> { print }' Pax.csv > Pax_1.csv
[mind@util1-pkl MHG_201406]$ cat Pax_1.csv
AccountCode,AccountName,UniqueCallId,FromNumber,ToNumber,DestinationDescription,CallType,CallDate,CallTime,CallDuration,CallDurationSec,Cost,0
563416,MHG - Braamfontein,3260306859:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,20-JUN-2014,17:03:56,00:00:05,5,0,0.00416667
563416,MHG - Braamfontein,3275326523:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,23-JUN-2014,14:19:07,00:00:20,20,0,0.00416667
563416,MHG - Braamfontein,3280178113:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,24-JUN-2014,08:06:23,00:00:06,6,0,0.00416667
563416,MHG - Braamfontein,3305018045:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,26-JUN-2014,10:32:13,00:00:06,6,0,0.00416667
563416,MHG - Braamfontein,3305020549:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,26-JUN-2014,10:32:22,00:00:04,4,0,0.00416667
563416,MHG - Braamfontein,3064064999:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,28-MAY-2014,12:05:07,00:00:06,6,0,0.00416667
563416,MHG - Braamfontein,3071554761:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,29-MAY-2014,09:12:05,00:00:20,20,0,0.00416667
563416,MHG - Braamfontein,3076236709:0A,0860101280,0113812027,Johannesburg area,VoIS Contact Sharecall Overflow,29-MAY-2014,14:07:51,00:00:01,1,0,0.00416667
563416,MHG - Braamfontein,3082567491:0A,0860101380,0214805963,Cape Town area,VoIS Contact Sharecall Overflow,30-MAY-2014,10:00:47,00:00:07,7,0,0.00416667
661178,MHG - Cape Town,3257924103:0A,0860102472,0214804774,Cape Town area,VoIS Contact Sharecall Overflow,20-JUN-2014,14:07:13,00:00:16,16,0,0.00416667
661178,MHG - Cape Town,3059920319:1830,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,28-MAY-2014,10:52:34,00:10:52,652,0,0.0226392
661178,MHG - Cape Town,3059920319:1890,0214804511,0860104111,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,28-MAY-2014,10:57:09,00:10:01,601,0,0.0208683
661178,MHG - Cape Town,3070357179:360,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,29-MAY-2014,08:46:20,00:20:39,1239,0,0.0430208
661178,MHG - Cape Town,3070357179:824,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,29-MAY-2014,09:35:03,00:18:44,1124,0,0.0390275
661178,MHG - Cape Town,3070357179:1103,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,29-MAY-2014,10:03:07,00:00:48,48,0,0.00166667
661178,MHG - Cape Town,3070357179:4351,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,29-MAY-2014,14:17:10,00:07:22,442,0,0.0153475
661178,MHG - Cape Town,3080634155:1403,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,30-MAY-2014,10:28:53,00:04:43,283,0,0.00982667
661178,MHG - Cape Town,3080634155:3172,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,30-MAY-2014,13:01:29,00:06:22,382,0,0.0132642
661178,MHG - Cape Town,3080634155:3622,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,30-MAY-2014,13:38:33,00:03:08,188,0,0.0065275
661178,MHG - Cape Town,3080634155:3648,0214804511,0860765633,Telkom Non-Geographic Universal Services,VoIS Community Sharecall,30-MAY-2014,13:41:42,00:19:29,1169,0,0.04059
[mind@util1-pkl MHG_201406]$

The output file name is Pax1.csv, please note that TelkomAsif hearder Changed to 0 in the output file.

Please note that the rates are not correct. They should either be 0.19 or 0.4 and TelkomAsif rate should be 0.5.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

csv file manipulation

Hi, I generated a csv file.But i have to manipulate it to make it user friendly. This is the structure of the input csv file. partyfailurereasonnumbercvfrejected12cvfapproved45cvfonhold23mvcunknown98mvconcall17pucapproved78puchold34actunknown19 The first line is the header. The... (6 Replies)
Discussion started by: amit.behera
6 Replies

2. Shell Programming and Scripting

csv manipulation

Hi, I want to delete the null values that are present in all the columns except the last column $ cat x.csv baseball,NULL,8798765,Most played,0,5,12367,NULL,NULL,98,67,Reason is not sufficient baseball,NULL,8928192,Most played,0,4,76893,NULL,RAW,54,78,NULL baseball,NULL,5678945,Most... (6 Replies)
Discussion started by: scripter12
6 Replies

3. Shell Programming and Scripting

Awk to convert a text file to CSV file with some string manipulation

Hi , I have a simple text file with contents as below: 12345678900 971,76 4234560890 22345678900 5971,72 5234560990 32345678900 71,12 6234560190 the new csv-file should be like: Column1;Column2;Column3;Column4;Column5 123456;78900;971,76;423456;0890... (9 Replies)
Discussion started by: FreddyDaKing
9 Replies

4. Shell Programming and Scripting

CSV data format manipulation

Hi There I need a script which will pick up the data from a .CSV file and reformat it as per the requirement and write it to another .CSV file. I am using an application that will only take data in a particular format and need something that will convert without manual intervention. The... (4 Replies)
Discussion started by: rbggbr16
4 Replies

5. Shell Programming and Scripting

Data Manipulation on a .csv file

Hallo Friends, I need you help. My file has 5000 or so lines and currently looks like below(sample). Service Type,Origin,Destination,Rate Per Minute,Minimum Charge,Time Based Rate,Time Based From Day,Time Based To Day,Time Based From Time,Time Based To Time,Destination Prefix List,, VoIS... (3 Replies)
Discussion started by: kekanap
3 Replies

6. Shell Programming and Scripting

Pax1.csv file manipulation

Hallo Team and happy Friday, I have a .csv file attached called MHG_Only_Billing_only_great_201408_SummaryDetails.csv The file is as below: $ cat MHG_Only_Billing_only_great_201408_SummaryDetails.csv... (1 Reply)
Discussion started by: kekanap
1 Replies

7. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

8. Shell Programming and Scripting

Save output of updated csv file as csv file itself

Hi, all I want to sort a csv file based on timestamp from oldest to newest and save the output as csv file itself. Here is an example of my csv file. test.csv SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0739.JPG,2015:02:17 11:32:21 /home/intannf/foto/IMG_0749.JPG,2015:02:17 11:37:28... (10 Replies)
Discussion started by: refrain
10 Replies

9. Shell Programming and Scripting

Save output of updated csv file as csv file itself, part 2

Hi, I have another problem. I want to sort another csv file by the first field. result.csv SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw /home/intannf/foto5/2015_0313_090651_219.JPG,0.,-7.77223,110.37310,30.75,996.46,148.75,180.94,182.00,63.92 ... (2 Replies)
Discussion started by: refrain
2 Replies
All times are GMT -4. The time now is 04:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy