Topic: Problem with AWK converter script
Hello,
I have some problem with data conversion, my data are received in the template like below (input.csv):
(ticker,periodicity,date,hour,popen,phigh,plow,pclose,volume)
FW20U09_I,1,20090619,083300,1928.00,1928.00,1927.00,1927.00,44
FW20U09_I,1,20090619,083400,1927.00,1929.00,1926.00,1928.00,48
FW20U09_I,1,20090619,083600,1926.00,1928.00,1926.00,1928.00,43
FW20U09_I,1,20090619,083900,1929.00,1930.00,1929.00,1930.00,76
FW20U09_I,1,20090619,084000,1929.00,1930.00,1929.00,1929.00,198
To convert this data I prepared file script.txt:
# AWK script
{
# Check the number of the columns
# We need of 9 columns
if(NF == 9)
{
# Input file
# -----------------
ticker = $1;
period = $2;
date = $3;
time = $4;
popen = $5;
phigh = $6;
plow = $7;
pclose = $8;
volume = $9;
# Convert the Date format from YYYYMMDD to YYYY-MM-DD
year = substr(date,1,4);
month = substr(date,5,2);
day = substr(date,7,2);
date = year "-" month "-" day;
# Converts the Time from HHMMSS to HH:MM
if(length(time) = 6)
{
hour = substr(time,1,2);
min = substr(3,2);
time = hour ":" min;
}
# Output file
# ------------------
print date ";" time ";" popen ";" phigh ";" plow ";" pclose ";" volume;
}
}
But I received empty output.csv file(0 bytes), where could be a problem?
Regards,