D
D
doitagain2014-08-14 21:18:21
linux
doitagain, 2014-08-14 21:18:21

How to remove an extra decimal point in a tick data set for an exchange instrument?

Hello guys. I have tick data for a stock in the form:
date, time, price, demand, supply, volume 09/28/2009, 09
:10:37,35.6,35.29,35.75,150
:06,35.48,35.34,35.64,14900
09/28/2009,09:30:06,35.49,35.37,35.61,100
09/28/2009,09:30:10,35.4,35.4,35.57,100
09/ 28/2009,09:30:10,35.48,35.43,35.53,200
09/28/2009,09
:30:11,35.459,35.44,35.56,200 35.49,35.57,100
separator - comma
In the last two lines, the price after the floating point has three digits.
I need to get rid of this third character so that these lines take the form:
09/28/
2009,09:30:11,35.45,35.44,35.56,200 ,100
and so on for the entire text file > 1GB in size
Thank you.
PS. Linux is not afraid, even mastered the command: sed -e 's/x/y/g' 1.txt > 2.txt

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xandox, 2014-08-15
@doitagain

/tmp$ cat test.awk
{
    P=$3
    PS=sprintf("%.2f", P)
    for (i = 1; i <= NF; ++i) {
        if (i != 1) printf FS
        if (i != 3) { printf $i } else { printf PS }
    }
    printf "\n"
}
/tmp$ cat test.txt | awk -f test.awk -F,
09/28/2009,09:10:37,35.60,35.29,35.75,150
09/28/2009,09:30:06,35.48,35.34,35.64,14900
09/28/2009,09:30:06,35.49,35.37,35.61,100
09/28/2009,09:30:10,35.40,35.4,35.57,100
09/28/2009,09:30:10,35.48,35.43,35.53,200
09/28/2009,09:30:11,35.46,35.44,35.56,200
09/28/2009,09:30:14,35.57,35.49,35.57,100

D
doitagain, 2014-09-17
@doitagain

Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question