awk 打印没有固定宽度格式的字符串?
有没有办法让 awk 不打印固定宽度的列?
例如:
"9", "TAYLOR TOWER, JACOB B. "
"9", "UNIVERSITY HOSPITALS-EAST"
"AR", "SCHOTTENSTEIN CENTER "
"B1", "NEWARK RESIDENCE HALL "
"B2", "NEWARK RESIDENCE HALL "
"CC", "OHIO STADIUM "
"D1", "TELECOM NETWORK CENTER "
"DC", "SCHOTTENSTEIN CENTER "
"EN", "SCHOTTENSTEIN CENTER "
"GR", "UNIVERSITY HOSPITALS-EAST"
"LL", "RANEY COMMONS, 2ND LT. AL"
"MZ", "PHYSICS RESEARCH "
"MZ", "SCHOTTENSTEIN CENTER "
"NS", "STARLING LOVING HALL "
"P1", "OHIO STADIUM "
"P2", "OHIO STADIUM "
"P3", "OHIO STADIUM "
我希望将其打印为:
"9", "TAYLOR TOWER, JACOB B."
"9", "UNIVERSITY HOSPITALS-EAST"
"AR", "SCHOTTENSTEIN CENTER"
"B1", "NEWARK RESIDENCE HALL"
"B2", "NEWARK RESIDENCE HALL"
"CC", "OHIO STADIUM"
"D1", "TELECOM NETWORK CENTER"
"DC", "SCHOTTENSTEIN CENTER"
"EN", "SCHOTTENSTEIN CENTER"
"GR", "UNIVERSITY HOSPITALS-EAST"
"LL", "RANEY COMMONS, 2ND LT. AL"
"MZ", "PHYSICS RESEARCH"
"MZ", "SCHOTTENSTEIN CENTER"
"NS", "STARLING LOVING HALL"
"P1", "OHIO STADIUM"
"P2", "OHIO STADIUM"
"P3", "OHIO STADIUM"
请注意,此文本中的第二个字段引号内没有空格。这可能吗?
Is there a way to have awk not print a fixed width column?
For example:
"9", "TAYLOR TOWER, JACOB B. "
"9", "UNIVERSITY HOSPITALS-EAST"
"AR", "SCHOTTENSTEIN CENTER "
"B1", "NEWARK RESIDENCE HALL "
"B2", "NEWARK RESIDENCE HALL "
"CC", "OHIO STADIUM "
"D1", "TELECOM NETWORK CENTER "
"DC", "SCHOTTENSTEIN CENTER "
"EN", "SCHOTTENSTEIN CENTER "
"GR", "UNIVERSITY HOSPITALS-EAST"
"LL", "RANEY COMMONS, 2ND LT. AL"
"MZ", "PHYSICS RESEARCH "
"MZ", "SCHOTTENSTEIN CENTER "
"NS", "STARLING LOVING HALL "
"P1", "OHIO STADIUM "
"P2", "OHIO STADIUM "
"P3", "OHIO STADIUM "
I want this to be printed as:
"9", "TAYLOR TOWER, JACOB B."
"9", "UNIVERSITY HOSPITALS-EAST"
"AR", "SCHOTTENSTEIN CENTER"
"B1", "NEWARK RESIDENCE HALL"
"B2", "NEWARK RESIDENCE HALL"
"CC", "OHIO STADIUM"
"D1", "TELECOM NETWORK CENTER"
"DC", "SCHOTTENSTEIN CENTER"
"EN", "SCHOTTENSTEIN CENTER"
"GR", "UNIVERSITY HOSPITALS-EAST"
"LL", "RANEY COMMONS, 2ND LT. AL"
"MZ", "PHYSICS RESEARCH"
"MZ", "SCHOTTENSTEIN CENTER"
"NS", "STARLING LOVING HALL"
"P1", "OHIO STADIUM"
"P2", "OHIO STADIUM"
"P3", "OHIO STADIUM"
Notice the second field in this text has no whitespace inside the quotes. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 AWK 中(gawk/nawk)
In AWK (gawk/nawk)
我会使用 sed 而不是 awk,尽管如果必须的话,您可以在 awk 中执行
gsub
:意思是“将行末尾的一个或多个空格后跟引号变成仅引号”
I'd use sed instead of awk, although you can do
gsub
in awk if you must:Meaning "turn one or more spaces followed by quote at the end of the line into just quote"