如何一次性剪切第一个字段的部分内容和其余字段?
以下是我正在工作的流程的输出。
10/19/2011 14:11:52.911728, 15277, 828, 2964, 1, 1
10/19/2011 14:11:53.915060, 34298, 898, 3096, 1, 1
但是,使用此输出,我需要生成每个的平均值 分钟。因此,我正在编写一个 shell 程序来输出所有这些,第一个字段仅显示小时和分钟,而不显示秒和微秒。
想知道从第一个字段和其余字段仅生成小时和分钟的最佳方法是什么。
我脑海中浮现的一个想法是,
cut -d"," -f2- source >file1
cut -d"," -f1 source | cut -d":" -f1,2 >file2
paste file2 file1
但这能一举实现吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果日期和时间是固定长度,则只需按列剪切:
如果除分钟之外的所有内容都可以是可变长度,请使用 sed:
If the dates and times are of fixed length, just cut by column:
If everything except minutes can be variable length, use sed: