Shell script help with function and output format
Greetings,
I'm new to writing shell scripts but after searching through this forum I've gotten most of what I want. However, I'm still having an issue. I am attempting to backload data from hundred's of large csv's into RRD. Essentially I want to parse out info from hundred's of columns in hundred's of files into 4 columns of data I want in one file. Essentially the date in unix time, the min, max, and average of a reading (say CPU) for the day, compiling all the days data into one file. The problem is I can't get my head around how to get the data to return on the same line. data: file1.csv 4 lines of headers I don't need 1-JUL-2006 17:41:00.00,111.42,xxx,yyy,zzz,etc.. 1-JUL-2006 17:42:00.00,69.87,xxx,yyy,zzz,etc.. 1-JUL-2006 17:43:00.00,101.10,xxx,yyy,zzz,etc.. etc... file2.csv 4 lines of headers I don't need 2-JUL-2006 17:41:00.00,111.42,xxx,yyy,zzz,etc.. 2-JUL-2006 17:42:00.00,69.87,xxx,yyy,zzz,etc.. 2-JUL-2006 17:43:00.00,101.10,xxx,yyy,zzz,etc.. etc.. What I have is: Code:
#!/bin/bash Code:
$ cat sum.awk 1153022400 min: 44.45 max: 666.22 average: 136.055 1153108800 min: 51.28 max: 1298.38 average: 374.275 etc... I realise why the data returns on two separate lines, and I thought it would be simple to correct, but no matter what I try I can't seem to get to my desired format of: 1153022400 min: 44.45 max: 666.22 average: 136.055 1153108800 min: 51.28 max: 1298.38 average: 374.275 etc... Thoughts? |
bit lost here, are you saying you're only looking at the very last line of each file? if so why is there a do loop there?
now presumably you simply want to get a timestamp to a variable, and then get the rrd data to a variable and then print them both? Code:
#!/bin/bash |
Hi,
Just looking at what you asked: Change this: date -d "$line" +%s # convert to unix time Into: thisDate=`date -d "$line" +%s` # convert to unix time echo -n $thisDate Make it a two step process. 1) put date in a variable, 2) output this variable using echo -n (or a printf construct if you like that better). The echo -n makes sure that there is no newline after it prints the date. Hope this helps. |
Quote:
Code:
#!/bin/bash 1153022400 min: 44.45 max: 666.22 average: 136.055 1153108800 min: 51.28 max: 1298.38 average: 374.275 Quote:
I works perfectly! Thanks very much to both of you for your help, especially druuna for providing the key that I was missing. cheers! |
Quote:
|
All times are GMT -5. The time now is 02:55 PM. |