Reputation: 1595
Following is the output of a process, that I am working.
10/19/2011 14:11:52.911728, 15277, 828, 2964, 1, 1
10/19/2011 14:11:53.915060, 34298, 898, 3096, 1, 1
However, using this output, I need to generate the average for each minute. Thus, I'm writing a shell program to just output all of these with the first field showing only hours and minutes and not the seconds and microseconds.
Wondering, what is the best way to generate only the hours and minutes from the first field and the rest of the fields.
One idea that comes to my mind is ,
cut -d"," -f2- source >file1
cut -d"," -f1 source | cut -d":" -f1,2 >file2
paste file2 file1
But can this be achieved in one shot?
Upvotes: 1
Views: 321
Reputation: 18008
If the dates and times are of fixed length, just cut by column:
$ cut -c1-15,26- < source
10/19/2011 14:18, 15277, 828, 2964, 1, 1
10/19/2011 14:10, 34298, 898, 3096, 1, 1
If everything except minutes can be variable length, use sed:
$ cat source
10/19/2011 14:11:52.911728, 15277, 828, 2964, 1, 1
10/19/2011 14:11:53.915060, 34298, 898, 3096, 1, 1
10/19/2011 4:11:53.915060, 34298, 898, 3096, 1, 1
$ sed 's/\([^:]*:..\)[^,]*\(, .*\)/\1\2/' < source
10/19/2011 14:11, 15277, 828, 2964, 1, 1
10/19/2011 14:11, 34298, 898, 3096, 1, 1
10/19/2011 4:11, 34298, 898, 3096, 1, 1
Upvotes: 2