有没有办法让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"
请注意,此文本中的第二个字段在引号内没有空格。这可能吗?
答案 0 :(得分:1)
我会使用sed而不是awk,但如果你必须在awk中执行gsub
:
sed -e 's/ *"$/"/'
含义“在行尾将一个或多个空格后跟引号改为引用”
答案 1 :(得分:1)
在AWK(gawk / nawk)中
{sub(/[ ]*\"$/, "\"");print}