Manipulating csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulating csv file
# 1  
Old 12-02-2010
Manipulating csv file

We need to convert a field in a csv file which is in cents to dollars.(divide by 100) in our shell script.
Can some body help me?
# 2  
Old 12-02-2010
you could try with bc..
Code:
CENT=70
DOL=$(echo "scale=3; ${CENT}/100" |bc)

# 3  
Old 12-02-2010
We are able to get the field from csv file using the command
cut -d , -f6 rpt.csv where f6 is the column with cent values.
But how do we convert that column into dollar?
# 4  
Old 12-02-2010
something like this...?
Code:
let i=1
while read F6
do
	DOL[$i]=$(echo "scale=3; ${F6}/100" |bc)
	i=$i+1
done < rpt_f6.csv 

echo "list of dollars: ${DOL[*]}"

or without the cut command you could directly read the f6 column
Code:
IFS=","
let i=1
while read F1 F2 F3 F4 F5 F6 F7 # assuming rpt.csv file contains 7 columns
do
	DOL[$i]=$(echo "scale=3; ${F6}/100" |bc)
	i=$i+1
done < rpt.csv

echo "list of dollars: ${DOL[*]}"


Last edited by michaelrozar17; 12-02-2010 at 04:28 AM.. Reason: added IFS..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

need help on manipulating a file

Hi, I need a shell/command to achieve this task. I've a delimited unloaded file from oracle in a scrambled format as shown below with many blank lines in it, I'm just trying to tailor it in a format that would be compatible to view and load it to a IDS db. Here is the problem ... (1 Reply)
Discussion started by: divak
1 Replies

3. Shell Programming and Scripting

Help Manipulating Large Csv File

Hello everyone, I am trying to manipulate a large .csv file where I have output similar to the following - http://imgur.com/TEXD8.png The result that I am looking for would be to consolidate the first column, but combine the second and third column so it still relates to the first. I... (8 Replies)
Discussion started by: xxwohxx
8 Replies

4. Shell Programming and Scripting

Manipulating a file

Hi everybody, I need an urgent help with a BASH script. I have file which contains (besides the other data) the lines with the following structure identified by with keyword PCList: <PARAMETER NAME="PCList" TYPE="LIST_STRUCTURE" MODEL="{,}" ... (1 Reply)
Discussion started by: sameucho
1 Replies

5. UNIX for Dummies Questions & Answers

Help!! manipulating file

Hi all, I need help manipulating the file below. Here is what I needed to do. First, I have to replace INSUPD to DELETE. Then I need to change the content of the file around by flipping the contents in the file from the bottom to the top (start from "CMD") How should I attack this? Here... (2 Replies)
Discussion started by: sirrtuan
2 Replies

6. Solaris

Manipulating File

Help...please. I have a log that contains Warning Authentication Failed: User GHDT88998HS doesn't exit: The User GHDT88998HS could not be found Mar 22, 2008 5:22:22AM com.hometel.ttm.auth.userlogin. about maybe a thousand entries failed user acct message How can I grab just the username... (2 Replies)
Discussion started by: rivendell500
2 Replies

7. Shell Programming and Scripting

manipulating csv to add extra row

hi how do i manipulate .csv file to add an extra row after each row using shell script? I need a blank line added for each 1000 records in my file? I will then need to copy and paste some data in the blank row created. thanks 4 ur support neil (3 Replies)
Discussion started by: neil546
3 Replies

8. Shell Programming and Scripting

Manipulating a text file

hey guys, need ur expert help. m a core banker got stuck in someting techie and cant find a solution have manged to extract a file from oracle apps in a format that looks something like this... REC- A b c d x INV- A b... (6 Replies)
Discussion started by: komalkg
6 Replies

9. UNIX for Advanced & Expert Users

Manipulating output file

I have a file containing two fields, Name and Time, with about 57 lines in this file. I am struggling to create a loop that will cut out the first ten lines of this file and echo it to the screen. Can anybody help me please. (1 Reply)
Discussion started by: mariner
1 Replies
Login or Register to Ask a Question