我如何在Shell中获得MCCLI输出中的定界符
在尝试处理“mccli Activity show”的输出(例如)时,输出可能如下所示:
ID Status Error Code Start Time Elapsed End Time Type Progress Bytes New Bytes
---------------- ------------------------ ---------- -------------------- ----------- -------------------- ---------------- ----------------- ---------
9133910640004809 Completed w/Exception(s) 10020 2012-06-07 18:00 EDT 00h:53m:46s 2012-06-07 18:53 EDT Scheduled Backup 215 0.2%
9133914600006909 Completed 0 2012-06-08 05:00 EDT 00h:00m:04s 2012-06-08 05:00 EDT Scheduled Backup 0 0%
Desired Output
ID, Status, Error Code, Start Time ,Elapsed ,End Time ,Type ,Progress Bytes ,New Bytes
----------------,------------------------, ---------- ,--------------------, -----------, --------------------, ---------------- ,----------------- ,---------
9133910640004809, Completed w/Exception(s), 10020, 2012-06-07 18:00 EDT, 00h:53m:46s ,2012-06-07 18:53 EDT, Scheduled Backup, 215 , 0.2%
9133914600006909, Completed , 0, ,2012-06-08 05:00 EDT, 00h:00m:04s ,2012-06-08 05:00 EDT, Scheduled Backup, 0 , 0%
Code I Tried
awk '!/---/{$1=x; sub(/,+$/,x)}1' OFS=,
but it does not work as it put comma for every space
In trying to process the output of "mccli activity show" (for example), the output might be like this:
ID Status Error Code Start Time Elapsed End Time Type Progress Bytes New Bytes
---------------- ------------------------ ---------- -------------------- ----------- -------------------- ---------------- ----------------- ---------
9133910640004809 Completed w/Exception(s) 10020 2012-06-07 18:00 EDT 00h:53m:46s 2012-06-07 18:53 EDT Scheduled Backup 215 0.2%
9133914600006909 Completed 0 2012-06-08 05:00 EDT 00h:00m:04s 2012-06-08 05:00 EDT Scheduled Backup 0 0%
Desired Output
ID, Status, Error Code, Start Time ,Elapsed ,End Time ,Type ,Progress Bytes ,New Bytes
----------------,------------------------, ---------- ,--------------------, -----------, --------------------, ---------------- ,----------------- ,---------
9133910640004809, Completed w/Exception(s), 10020, 2012-06-07 18:00 EDT, 00h:53m:46s ,2012-06-07 18:53 EDT, Scheduled Backup, 215 , 0.2%
9133914600006909, Completed , 0, ,2012-06-08 05:00 EDT, 00h:00m:04s ,2012-06-08 05:00 EDT, Scheduled Backup, 0 , 0%
Code I Tried
awk '!/---/{$1=x; sub(/,+$/,x)}1' OFS=,
but its not working as its putting comma for every space
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的预期输出并没有真正的意义(例如,一个明显字段的
0,
的明显字段的逗号,有时您在逗号之前,有时在逗号之前,有时在其之前和之后都有空白)和我认为您的示例输入不是准确的(例如215
和0.2%
看起来太近了),所以我猜是 - 但是 - 使用GNU AWK用于fiedwidths < /code>和
nextfile
,这可能是您真正想做的:或者:
You posted expected output doesn't really make sense (e.g. 2 commas for one apparent field at
0, ,
and sometimes you have blanks before the comma, sometimes after it, and sometimes before AND after it) and I think your sample input isn't accurate (e.g.215
and0.2%
appears too close together) so I'm guessing but - using GNU awk forFIEDWIDTHS
andnextfile
, this may be what you really want to do:or: