The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Date Calculations mitschcg UNIX for Dummies Questions & Answers 8 03-06-2009 04:40 AM
ksh, calculations using bc cesarNZ Shell Programming and Scripting 2 12-14-2008 10:42 PM
how do you get input of a file to calculations nadman123 Shell Programming and Scripting 6 04-11-2008 04:14 AM
Time Calculations Nysif Steve UNIX for Dummies Questions & Answers 5 09-14-2007 09:49 AM
Float calculations sharmavr UNIX for Dummies Questions & Answers 1 07-26-2006 03:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-25-2009
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
calculations in awk/sed

Hi friends,

I am in a little confusion.
I have a comma separated file contains hugh records.
say,


Code:
88562848,21-JAN-08,2741079, -1188,-7433,TESTING
88558314,21-JAN-08,2741189, -1273,-7976,TESTING

I want 4th and 5th field to be multiplied by 100.

like,
88562848,21-JAN-08,2741079, -118800,-743300,TESTING
88558314,21-JAN-08,2741189, -127300,-797600,TESTING


Is this can be done by sed? or any by other efficient way?
Please suggest.

Thanks in advance.

Last edited by Yogesh Sawant; 03-25-2009 at 05:01 AM.. Reason: added code tags
  #2 (permalink)  
Old 03-25-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,934

Code:
$ cat csv.txt
88562848,21-JAN-08,2741079, -1188,-7433,TESTING
88558314,21-JAN-08,2741189, -1273,-7976,TESTING
$ awk -F, '{$4*=100;$5*=100;print $1","$2","$3","$4","$5","$6}' csv.txt
88562848,21-JAN-08,2741079,-118800,-743300,TESTING
88558314,21-JAN-08,2741189,-127300,-797600,TESTING
$

  #3 (permalink)  
Old 03-25-2009
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
Hi Pludi,

Thanks for the solution.
Its working.


-Anchal
  #4 (permalink)  
Old 03-26-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,089

Code:
awk -F"," '{$4*=100;$5*=100;print}' filename

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0